嗨,有人会帮助我如何获得所有价值“clickUrl”,
我正在使用file_get_content函数,我想将其包装在html中
<?PHP
$json_url = "someone.web.id";
$json = file_get_contents($json_url);
$json=str_replace('},]',"}]",$json);
$data = json_decode($json);
echo "<pre>";
print_r($data);
echo "</pre>";
?>
我的结果是
stdClass Object
(
[serialId] => 110153837
[productId] => 212065382
[os] => Linux
[validResponse] => 1
[errorMessage] =>
[adsDetails] => Array
(
[0] => stdClass Object
(
[requestTimestamp] => 1429665317403
[adId] => SAP_272131
[clickUrl] => http://adtrack.king.com
)
[1] => stdClass Object
(
[requestTimestamp] => 1429679659674
[adId] => SAP_182149
[clickUrl] => market://details?id
)
[2] => stdClass Object
(
[requestTimestamp] => 1429679659674
[adId] => SAP_552219
[clickUrl] => http://t.mobitrk.com
)
[3] => stdClass Object
(
[requestTimestamp] => 1429679659674
[adId] => SAP_562515
[clickUrl] => https://app.adjust.io
)
)
)
我不知道为什么我的早期帖子被meagar删除了
解决方法:
从stdobject更改为数组并在其周围循环.
要将JSON作为数组接收,只需更改:
$data = json_decode($json);
对此:
$data = json_decode($json,true);
然后,循环…
foreach ($data['adsDetails'] as $innerArray) {
echo $innerArray['requestTimestamp'].'<br>';
echo $innerArray['adId'].'<br>';
echo $innerArray['clickUrl'].'<br>';
}