chasethemetal Posted December 10, 2011 Share Posted December 10, 2011 Hey all! Thanks again for the help on my earlier problems, much appreciated!!! I've got a new question dealing with json, as I am just beginning to fiddle with it! How would I echo out specific parts of this code in php? See json below. Thanks!! [{"people":[{"name":"bob","url":"http:\/\/www.bob.com","id":null}], "url":"http:\/\/www.site.com","status":"available","id":"1111111","datetime":null, "place": {"city":"Brooklyn","name":"Gallery","latitude":"40.7186480","region":"NY","country":"United States","url":"http:\/\/www.place.com","id":"222222","longitude":"-73.9602690"}, "datetime":"2012-01-28T20:00:00","t_url":"http:\/\/www.t.com/"}] Link to comment Share on other sites More sharing options...
birbal Posted December 10, 2011 Share Posted December 10, 2011 http://php.net/json_decode Link to comment Share on other sites More sharing options...
chasethemetal Posted December 10, 2011 Author Share Posted December 10, 2011 Thanks. I've read that page, json_decode puts it into an array. But there are no examples on that page showing you how to get data that is as nested as the feed I'm getting. I f anyone could point me to a site that has examples where the data is similar to mine that would be great! Or show me a snippet here! Link to comment Share on other sites More sharing options...
thescientist Posted December 10, 2011 Share Posted December 10, 2011 have you tried using loops? That's most common technique of traversing arrays to get to their contents. for each level of nesting, you will need to use another loop. This unless you know specifically what you need in and the direct path to get to it. Link to comment Share on other sites More sharing options...
chasethemetal Posted December 10, 2011 Author Share Posted December 10, 2011 Yeah my purposed I'm trying to get specific information, so I guess you would say I know the direct path. Link to comment Share on other sites More sharing options...
thescientist Posted December 10, 2011 Share Posted December 10, 2011 so what's the problem? If you don't know how to use array's you should read about them.http://www.w3schools.com/php/php_arrays.asp Link to comment Share on other sites More sharing options...
chasethemetal Posted December 10, 2011 Author Share Posted December 10, 2011 Well let me show you my confusion. Let see I'm trying to echo 'name' from my json list above... The json_encode($json, true) outputs this snippet.. array(1) { [0]=> array(8) { ["people"]=> array(1) { [0]=> array(3) { ["name"]=> string(3) "bob" ["url"]=> string(19) "http://www.bob.com" ["id"]=> NULL } } There more at the end... But just by looking at array examples and the such my logic tells me to do this (assume this is $arr). echo $arr[0]['people'][0]['name']; Link to comment Share on other sites More sharing options...
chasethemetal Posted December 10, 2011 Author Share Posted December 10, 2011 figured it out. thanks for the references. foreach ($arr as $value){echo $value['people'][0]['name']. "<br />";}; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.