I have an API that I am using that is essentially returning data you would expect to see in array, but in a format where it is one long string of information. It looks a bit like this: {"results":[{"NodeID":1,"Icon":"9.gif ","DisplayName":"Device 1"},{"NodeID":2,"Icon":"9.gif ","DisplayName":"Device 2"},{"NodeID":3,"Icon":"9.gif ","DisplayName":"Device3"}]} I have a site written in basic php and is using "file_get_contents" with a formatted url to get this info. Is there any way that I can format this string into an array with alternating values for NodeID, Icon, and DisplayName? Essentially something like this for the above string: "1, 9.gif, Device1, 2, 9.gif, Device2, 3, 9.gif, Device3" Any ideas? Thank you in advance!
I'm pretty sure that's not "a long string of information" but a JSON-encoded result. Just do a $result = json_decode($data,true); to get an associative array for the values (you'll then access it something like $result[0][NodeID] and so forth.
That is indeed JSON encoded data, it makes a lot more sense if you format it. { "results" : [ { "NodeID" : 1, "Icon" : "9.gif ", "DisplayName" : "Device 1" }, { "NodeID" : 2, "Icon" : "9.gif ", "DisplayName" : "Device 2" },{ "NodeID" : 3, "Icon" : "9.gif ", "DisplayName" : "Device3" } ] } Code (markup): and a json_decode of it: http://php.net/manual/en/function.json-decode.php Would give you this array structure: stdClass Object ( [results] => Array ( [0] => stdClass Object ( [NodeID] => 1 [Icon] => 9.gif [DisplayName] => Device 1 ) [1] => stdClass Object ( [NodeID] => 2 [Icon] => 9.gif [DisplayName] => Device 2 ) [2] => stdClass Object ( [NodeID] => 3 [Icon] => 9.gif [DisplayName] => Device3 ) ) ) Code (markup): So for example if you did: $test = json_decode($jsonString); Where $jsonString contained that data from your post, $test['results'][2]['DisplayName'] would be 'Device 3'.