次のPHPコードを使用してjson文字列を返します。
$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];
次のようなjson文字列を取得します。
[{"ID": "123"、 "説明": "チャンピオンフットボールネイビーTシャツ"、 "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 "、"説明":"チャンピオンフットボールネイビーTシャツ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 ":" "} ]"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": ""}]"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": ""}]http://www.mystore.com/mainstore/045.jpg "、" ThumbnailImageURL ":" http://www.mystore.com/mainstore/045.jpg "、" MiniImageURL ":" http://www。 mystore.com/mainstore/045.jpg "、" AffiliateID ":""}]http://www.mystore.com/mainstore/045.jpg "、" ThumbnailImageURL ":" http://www.mystore.com/mainstore/045.jpg "、" MiniImageURL ":" http://www。 mystore.com/mainstore/045.jpg "、" AffiliateID ":""}]
ただし、$ response [0]をエコーすると、文字列全体が取得されます。json_decodeまたはencodeを使用すると、文字列が取得されますが、引用符で囲まれています。このダングなものをキャストする方法がわからないので、オブジェクトの配列として動作し、それを反復処理できます。事前に助けてくれてありがとう