【发布时间】:2021-12-09 05:40:09
【问题描述】:
我有一个返回 json 的 url。我想循环获取json中的每个值。
这就是我的 json 的样子。
{"error":false,
"message":"Request orders successfully completed",
"orders":[{
"oid":505,
"uid":234,
"total_amount":"143.99000"
},
{
"oid":506,
"uid":234,
"total_amount":"1.19000"
}]
}
我的 PHP 代码
$getOrdersUrl = file_get_contents("https://apiurl?last_id=504");
$json = json_decode($getOrdersUrl, true);
if(!empty($json)){
foreach($json as $val)
{
$oid = $val['orders'][0]['oid'];
$uid = $val['orders'][0]['uid'];
$total_amount = $val['total_amount'];
echo $oid;
}
}else{
echo "No Data to fetched to fetch for <br>";
}
【问题讨论】:
-
你想要
foreach($json['orders'] as $order),然后是$order['oid']等等