How to decode this JSON string?

this is what I get as a string from the URL of the search appliance (JSON Encoded):

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

How can I decode it using json_decode () function in php and get the last element of the array ("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..

+2
json php
source share
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 the second parameter.

Update:

How to feed value in JSON

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

- an array of objects, the contents of $array['feed'] :

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

To get the url you need to access the array using $array['feed'][0]['href'] or $feed[0]['href'] .

But this is the main processing of arrays. Array documentation might help you.

+2
source share

All Articles