Supporto 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 risposte (nella pagina 1 di 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.

Non riesci a trovare un film o una serie Tv? Accedi per crearlo.

Globale

s focalizza la barra di ricerca
p apri menu profilo
esc chiudi una finestra aperta
? apri finestra scorciatoia tastiera

Su tutte le pagine di media

b torna indietro (o al precedente quando applicabile)
e vai alla pagina di modifica

Nelle pagine delle stagioni TV

(freccia destra) vai alla stagione successiva
(freccia sinistra) vai alla stagione precedente

Nelle pagine degli episodi TV

(freccia destra) vai all'episodio successivo
(freccia sinistra) vai all'episodio precedente

Su tutte le pagine di immagini

a apri finestra aggiungi immagine

Su tutte le pagine di modifica

t apri selettore traduzione
ctrl+ s invia modulo

Sulle pagine di discussione

n crea nuova discussione
w segna come visto/non visto
p cambia publico/privato
c cambia chiuso/aperto
a apri attivita
r rispondi alla discussione
l vai all'ultima risposta
ctrl+ enter invia il tuo messaggio
(freccia destra) pagina successiva
(freccia sinistra) pagina precedente

Impostazioni

Vuoi valutare o aggiungere quest'elemento a una lista?

Accedi