This question already has an answer here:
这个问题在这里已有答案:
- How can I access an array/object? 4 answers
如何访问数组/对象? 4个答案
JSON data
"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
}]
In 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>";}
}
But I am getting below error message,
但我收到以下错误信息,
Notice: Trying to get property of non-object in ....
注意:试图获取非对象的属性....
How can I echo data inside "billing_details" object under array "orders" ?
如何在数组“orders”下的“billing_details”对象内回显数据?
2 个解决方案
#1
1
Try this
$json_output = json_decode($response['orders']);
$ json_output = json_decode($ response ['orders']);
echo $json_output;
#2
1
Try this:
$json_output = json_decode($response);
foreach ($json_output['orders'] as $billing_details) {
echo "<b>Name:</b><br>$billing_details['firstname'] $billing_details['lastname']<br>";}
#1
1
Try this
$json_output = json_decode($response['orders']);
$ json_output = json_decode($ response ['orders']);
echo $json_output;
#2
1
Try this:
$json_output = json_decode($response);
foreach ($json_output['orders'] as $billing_details) {
echo "<b>Name:</b><br>$billing_details['firstname'] $billing_details['lastname']<br>";}