small Posted February 26, 2010 Share Posted February 26, 2010 == PHP json decode == I'm trying to print a nested variable ("url") from a json response in php 5.3. Json code <code> { "offset": "0", "results": [ { "body": "body info", "date": "date info", "title": "title info", "url": "url info" } ], "total": 1 } </code> My current php code $info = json_decode($jsonresponse); print $info->{"results"}->{"url"};//this doesn't work How would I print the value of the "url" variable in php? (This should be fairly simple...) Link to comment https://forums.phpfreaks.com/topic/193447-print-out-nested-json-variable/ Share on other sites More sharing options...
trq Posted February 26, 2010 Share Posted February 26, 2010 Not tested but looks more like it. print $info->results[0]->url; Link to comment https://forums.phpfreaks.com/topic/193447-print-out-nested-json-variable/#findComment-1018433 Share on other sites More sharing options...
small Posted February 26, 2010 Author Share Posted February 26, 2010 Ye I figured it out. It should be $info = json_decode($xml,true); print $info["results"][0]["url"]; Didn't realize it was a 0 in the middle. Thanks! Link to comment https://forums.phpfreaks.com/topic/193447-print-out-nested-json-variable/#findComment-1018441 Share on other sites More sharing options...
trq Posted February 26, 2010 Share Posted February 26, 2010 If that works, then so will.... $info = json_decode($xml); print $info->results[0]->url; Link to comment https://forums.phpfreaks.com/topic/193447-print-out-nested-json-variable/#findComment-1018445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.