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 回复(第 1 页,共 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 发送信息
(右箭头)下一页
(左箭头)前一页

设置

想给这个条目评分或将其添加到片单中?

登录

还不是会员?

注册加入社区