Lezzetli API json yanıt ile Çalışma

4 Cevap php

Ben lezzetli imleri toplam sayısını bulmaya çalıştığınızda, Delicious çözümlenmiş zaman bir json dosyası döndürür:

Array ( 
    [0] => stdClass Object ( 
        [hash] => e60558db2d649c8a1933d50f9e5b199a 
        [title] => ISRAEL: Thousands march in Jerusalem rally, Israel still kicking 
                       new families out of land they've owned for 60+ years 
        [url] => http://english.aljazeera.net/news/middleeast/2010/03/2010362141312196.html
        [total_posts] => 2 
        [top_tags] => Array () 
     )
)

Dizi stdClass Object. Nasıl PHP kullanarak [TOTAL_COUNT] elde edebilirsiniz.

P.S Since I could not figure out how to extract it, I am using strpos to find 'total_count' and then I am cutting the string from that position and then extracting integers out of it. :) BUt it is way too long.

Solved

4 Cevap

Eğer ikinci argüman ise, true, bir nesneye karşı sizin json_decode, düzenli bir dizi döndürür içinde. Sizinle çalışmak için bu daha kolay bulabilirsiniz.

$array = json_decode($json, true);

Eğer json_decode gerçek bir ikinci argüman, geçerseniz bir nesne aksine, düzenli bir dizi döndürür. Sizinle çalışmak için bu daha kolay bulabilirsiniz.

$array = json_decode($json, true);

Denedin

echo $stdClass->total_posts;

Eğer [total_posts] demek? Eğer öyleyse, kullanmalısınız $delArray[0]->total_posts.

Nesne özelliklerine erişme örnekleri için http://us.php.net/manual/en/language.types.object.php bakın.