我有json数据我想在我告诉你之前选择一些数据,请仔细阅读数据。
{
"response": {
"status": 1,
"httpStatus": 200,
"data": [{
"offer_id": "6912",
"Thumbnail": {
"10116": {
"id": "10116",
"offer_id": "6912",
"display": "Icandytv_IN_Call-30-19-20-51).gif",
"thumbnail": "https:\/\/media.go2speed.org\/brand\/files\/mobvista\/6912\/thumbnails_100\/Icandytv_IN_Call(04-30-19-20-51).gif"
}
}
}],
"errors":[] ,
"errorMessage": null
}
}
从上面数据我想收集thumbnail plese的值帮助我使用PHP找到它
答案 0 :(得分:0)
也许这是一个复制/粘贴问题,但是你的JSON-String缺少一些}
。但这不是问题。如果您想在json中访问thumbnail
(小写),请尝试以下操作:
<?php
$json = '{"response": {"status":1,"httpStatus":200,"data":[{"offer_id":"6912","Thumbnail":{"10116":{"id":"10116","offer_id":"6912","display":"Icandytv_IN_Call (04-30-19-20-51).gif","thumbnail":"https://media.go2speed.org/brand/files/mobvista/6912/thumbnails_100/Icandytv_IN_Call(04-30-19-20-51).gif"}}}],"errors":[],"errorMessage":null}}';
// Make JSON accessible for PHP
$data = json_decode($json);
// Get access to Thumbnail object
$thumbnail0 = $data->response->data[0]->Thumbnail;
// Get access to thumbnail object "10116"
$thumbnail_10116 = $thumbnail0->{"10116"};
// Thumbnail Url
$thumbnailUrl = $thumbnail_10116->thumbnail;
echo $thumbnailUrl . "\n";
// or in one swoop
$thumbnailUrl2 = $data->response->data[0]->Thumbnail->{"10116"}->thumbnail;
echo $thumbnailUrl2 . "\n";
?>
希望,这有帮助