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 replies (on page 1 of 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.

映画やテレビ番組が見つかりませんか?ログインして作成してください。

全般

s 検索バーに移動する
p プロファイルメニューを開く
esc 開いているウィンドウを閉じる
? キーボードショートカットウィンドウを開く

メディアのページ

b 戻る(または該当する場合は親に)
e 編集ページに行く

テレビ番組のシーズンのページ

(右矢印)次のシーズンに行く
(左矢印)前のシーズンに戻る

テレビ番組のエピソードのページ

(右矢印)次のエピソードに進む
(左矢印)前のエピソードに戻る

全ての画像のページ

a 画像追加ウィンドウを開く

全ての編集ページ

t 翻訳選択を開く
ctrl+ s フォームを送信する

ディスカッションのページ

n 新しいディスカッションを作成する
w 監視ステータスを切り替える
p 公開/非公開を切り替える
c 閉じる/開くを切り替える
a アクティビティを開く
r ディスカッションに返信
l 最後の返事に行く
ctrl+ enter メッセージを送信する
(右矢印)次のページ
(左矢印)前のページ

設定

このアイテムを評価したり、リストに追加したりしたいですか?

ログイン

メンバーではありませんか?

登録してコミュニティに参加