دعم الموقع

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 أرسل رسالتك
(السهم الايمن) الصفحة التالية
(السهم الايسر) الصفحة السابقة

الاعدادات

هل تريد تقييم او اضافة هذا العنصر للقائمة؟

تسجيل الدخول