Suporte do The Movie Database

When i search a Tv with query: https://api.themoviedb.org/3/search/tv?page=1&query=Malcolm%20In%20The%20Middle&language=fr&api_key=XXXXXXX, i want just the name of the serie but i don't know how do this, bceause the "results" is a json array. Help me please.

Sorry my langage is french and not english

7 respostas (na página 1 de 1)

Jump to last post

Hi @XPheNiiXz You'll have to iterate over the array. Every language is going to be slightly different, but it's just an array so it's as easy as iterating over it and doing what you want with each object. Here's a simple print:

require 'uri'
require 'net/http'
require 'json'

api_key = YOUR_API_KEY'
url = URI("https://api.themoviedb.org/3/search/tv?include_adult=false&page=1&language=fr-FR&api_key=#{api_key}&query=malcolm+in+the+middle")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
body = JSON.parse(response.read_body)
2.2.3 :042 > body['results'].count
 => 1
2.2.3 :074 > body['results'].each { |item| puts "Name: #{item['name']}, Air Date: #{item['first_air_date']}" }
 => "Name: Malcolm, Air Date: 2000-01-09"

Thank you for your reply @travisbell . How can I do in php ? :)

Because my json is:


{"page":1,"results":[{"poster_path":"\/8I6xRdYBZhmGV0cKBGZZSham12T.jpg","popularity":6.314043,"id":2004,"backdrop_path":"\/8VmOlxllljk6AiamMK8odBFNKl5.jpg","vote_average":7.12,"overview":"Petit génie malgré lui, Malcolm vit dans une famille hors du commun. Le jeune surdoué n'hésite pas à se servir de son intelligence pour faire les 400 coups avec ses frères : Francis, l'aîné, envoyé dans une école militaire après une bêtise de trop, Reese, une brute pas très maligne, et Dewey, le petit dernier, souffre douleur général. Les parents tentent tant bien que mal de canalyser l'énergie de ces petits démons. Si Loïs est despotique et veut tout contrôler, Hal, en revanche, est irresponsable et ne pense qu'à s'amuser.","first_air_date":"2000-01-09","origin_country":["US"],"genre_ids":[35],"original_language":"en","vote_count":65,"name":"Malcolm","original_name":"Malcolm in the Middle"}],"total_results":1,"total_pages":1} 

And i just want the original name or the poster path, but i can't :(

I can have the page but not any item in the results

I have an aray too:

array(2) {
  [0]=>
  object(stdClass)#2 (13) {
    ["poster_path"]=>
    string(32) "/tptIMKRPHPEnnlzSgzvJIF1Rguk.jpg"
    ["popularity"]=>
    float(38.140215)
    ["id"]=>
    int(456)
    ["backdrop_path"]=>
    string(32) "/f5uNbUC76oowt5mt5J9QlqrIYQ6.jpg"
    ["vote_average"]=>
    float(6.87)
    ["overview"]=>
    string(371) "Les Simpson, famille américaine moyenne, vivent à Springfield. Homer, le père, a deux passions : regarder la télé et boire des bières. Mais son quotidien est rarement reposant, entre son fils Bart qui fait toutes les bêtises possibles, sa fille Lisa qui est une surdouée, ou encore sa femme Marge qui ne supporte pas de le voir se soûler à longueur de journée."
    ["first_air_date"]=>
    string(10) "1989-12-16"
    ["origin_country"]=>
    array(1) {
      [0]=>
      string(2) "US"
    }
    ["genre_ids"]=>
    array(3) {
      [0]=>
      int(16)
      [1]=>
      int(35)
      [2]=>
      int(10751)
    }
    ["original_language"]=>
    string(2) "en"
    ["vote_count"]=>
    int(404)
    ["name"]=>
    string(11) "Les Simpson"
    ["original_name"]=>
    string(12) "The Simpsons"
  }
  [1]=>
  object(stdClass)#3 (13) {
    ["poster_path"]=>
    string(32) "/tqpCdw3Njfxu9kdDTwxeLOQWTyu.jpg"
    ["popularity"]=>
    float(1.058557)
    ["id"]=>
    int(12595)
    ["backdrop_path"]=>
    NULL
    ["vote_average"]=>
    int(0)
    ["overview"]=>
    string(0) ""
    ["first_air_date"]=>
    string(0) ""
    ["origin_country"]=>
    array(1) {
      [0]=>
      string(2) "US"
    }
    ["genre_ids"]=>
    array(0) {
    }
    ["original_language"]=>
    string(2) "en"
    ["vote_count"]=>
    int(0)
    ["name"]=>
    string(38) "The Tracey Ullman Show Simpsons Shorts"
    ["original_name"]=>
    string(38) "The Tracey Ullman Show Simpsons Shorts"
  }
}

Unfortunately, I can't answer your question about PHP as I have never used it.

Best thing I can suggest is taking a look at one of the PHP libraries and either use one, or at the very least look at how some of the responses are handled in PHP.

Cheers.

Thanks i will look at

I find how do this.

Thank you.

Não consegue encontrar um certo filme ou série? Inicie sessão e adicione-o.

Geral

s focus the search bar
p abrir menu do perfil
esc close an open window
? open keyboard shortcut window

Em páginas de Média

b go back (or to parent when applicable)
e ir para a página de edição

Em páginas de temporadas de séries

(seta para a direita) ir para a próxima temporada
(seta para a esquerda) ir para a temporada anterior

Em Páginas de Episódios de Séries

(seta para a direita) ir para o próximo episódio
(seta para a esquerda) ir para o episódio anterior

Em Todas as Páginas de Imagens

a abrir janela para adicionar imagem

Em Todas as Páginas de Edição

t open translation selector
ctrl+ s submit form

Em Páginas de Discussão

n criar uma nova discussão
w toggle watching status
p toggle public/private
c toggle close/open
a abrir actividade
r reply to discussion
l ir para a última resposta
ctrl+ enter submit your message
(seta para a direita) página seguinte
(seta para a esquerda) página anterior

Definições

Deseja classificar ou adicionar este item a uma lista?

Iniciar Sessão

Ainda não é um membro?

Crie uma Conta e Adere a Comunidade