I'm using the following PHP code to return a json string:
$itemURL = 'http://***.***.***/search?tag=Football&affiliate_id=&max_results=3';
$response = file_get_contents($itemURL);//curl_exec($curlHandle);
echo $response;
$response = array($response);
echo $response[0];
I get a json string that looks something like this:
[ { "ID": "123", "Description": "Champion Football Navy T-shirt", "HighPrice": 16.99, "LowPrice": 16.99, "SalePrice": null, "OnSale": false, "URL": "http://www.mystore.com/itemDescription", "ImageURL": "http://www.mystore.com/mainstore/045.jpg", "LargeImageURL": "http://www.mystore.com/mainstore/045.jpg", "ThumbnailImageURL": "http://www.mystore.com/mainstore/045.jpg", "MiniImageURL": "http://www.mystore.com/mainstore/045.jpg", "AffiliateID": "" }, { "ID": "23", "Description": "Champion Football Navy T-shirt XL", "HighPrice": 16.99, "LowPrice": 16.99, "SalePrice": null, "OnSale": false, "URL": "http://www.mystore.com/itemDescription", "ImageURL": "http://www.mystore.com/mainstore/045.jpg", "LargeImageURL": "http://www.mystore.com/mainstore/045.jpg", "ThumbnailImageURL": "http://www.mystore.com/mainstore/045.jpg", "MiniImageURL": "http://www.mystore.com/mainstore/045.jpg", "AffiliateID": "" } ]
However when I echo $response[0] I get the entire string. If I use json_decode or encode I get a string but with quotes around it. I can't figure out how to cast this dang thing so it operates as an array of objects that I can then iterate through. Thanks for any help in advance
json_decode($response)(placed right after it is set fromfile_get_contents) does not return an object?