使用 php 从 JSON 对象中选择数据
Selecting Data from JSON object using php
我有json数据我想要select一些数据在我告诉你之前请仔细阅读数据。
{
"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
}
}
从上面的数据我想收集缩略图的值请帮助我使用 PHP
找到它
也许这是一个 copy/paste 问题,但是您的 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";
?>
希望,这有帮助
我有json数据我想要select一些数据在我告诉你之前请仔细阅读数据。
{
"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
}
}
从上面的数据我想收集缩略图的值请帮助我使用 PHP
找到它也许这是一个 copy/paste 问题,但是您的 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";
?>
希望,这有帮助