【发布时间】:2017-04-20 20:05:06
【问题描述】:
JSON 数据
"orders":[
"billing_details":{
"company":"Test Company",
"firstname":"Munadil",
"postcode":"5000",
"street":"Dhaka, Bangladesh",
"email":"munadil98@gmail.com",
"lastname":"Fahad",
"ph_number":"880191111111",
"city":"Dhaka",
"state":"Mirpur",
"country_code":"BN",
"user_id":16003511,
"salutation":null
}]
在 PHP 中
$json_output = json_decode($response);
foreach ( $json_output->orders as $orders ){
foreach ($orders->billing_details as $billing_details) {echo "<b>Name:</b><br>".$billing_details->firstname." ".$billing_details->lastname."<br>";}
}
但我收到以下错误消息,
注意:试图在....中获取非对象的属性。
如何在数组“orders”下的“billing_details”对象中回显数据?
【问题讨论】:
-
billing_details是数组中的键。试试"orders":[{...}] -
你在哪里声明了变量 $orders?
-
那是无效的 JSON。
-
@mike.k 请提及确切的语法以在 billing_details 中回显值
-
@MunadilFahad 首先请更正你的 json,因为你上面显示的那个是无效的!