Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

this is what i get as a string from a feed finder url (JSON Encoded):

{
  "updated": 1265787927,
  "id": "http://www.google.com/reader/api/0/feed-finder?qu003dhttp://itcapsule.blogspot.com/u0026outputu003djson",
  "title": "Feed results for "http://itcapsule.blogspot.com/"",
  "self": [{
    "href": "http://www.google.com/reader/api/0/feed-finder?qu003dhttp://itcapsule.blogspot.com/u0026outputu003djson"
  }],
  "feed": [{
    "href": "http://itcapsule.blogspot.com/feeds/posts/default"
  }]
}

How can i decode it using json_decode() function in php and get the last array element ("feed") ? i tried it with the following code but no luck

 $json = file_get_contents("http://www.google.com/reader/api/0/feed-finder?q=http://itcapsule.blogspot.com/&output=json");
 $ar = (array)(json_decode($json,true));
 print_r $ar;

Please help ..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
205 views
Welcome To Ask or Share your Answers For Others

1 Answer

$array = json_decode($json, true);
$feed = $array['feed'];

Note that json_decode() already returns an array when you call it with true as second parameter.

Update:

As the value of feed in JSON

"feed":[{"href":"http://itcapsule.blogspot.com/feeds/posts/default"}]

is an array of objects, the content of $array['feed'] is:

Array
(
    [0] => Array
        (
            [href] => http://itcapsule.blogspot.com/feeds/posts/default
        )  
)

To get the URL you have to access the array with $array['feed'][0]['href'] or $feed[0]['href'].

But this is basic handling of arrays. Maybe the Arrays documentation helps you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...