i need to translate this json into a php array then cycle through the items and put them into there respective columns i have tried using json decode on it own but all i get back is the text array i know the request works fine and gives the following output :
[{"roomType":"Single rooms","roomTypeCode":"SB"},{"roomType":"Double rooms","roomTypeCode":"DB"},{"roomType":"Twin rooms","roomTypeCode":"TB"},{"roomType":"Triple rooms","roomTypeCode":"TR"},{"roomType":"Suites","roomTypeCode":"S"},{"roomType":"Non-smoking rooms","roomTypeCode":"NS"},{"roomType":"Quad rooms","roomTypeCode":"Q"},{"roomType":"Twin for sole use","roomTypeCode":"TS"}]
if i print the string that needs to be decoded its all there but json decode doesn't seem to be able to just but this into an associative array the way im trying to use it heres the request
$ch = curl_init();
$timeout = 0;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdatar = curl_exec($ch);
curl_close($ch);
$roomdata = json_decode($rawdatar);
print $roomdata;
if i print $rawdatar i get the aforementioned line of json but nothing but Array when i print $roomdata what am i doing wrong
var_dump()
to see what you got instead ofprint
. – fdomig Aug 10 '12 at 18:40