[英]accessing a json.parse multidimensional array php
我有以下json:-
{
"firstName": "Jhon",
"lastName": "Doe",
"username": "jhon",
"avatar": "localhost/uploads/avatars/default.jpg",
"language": "ar",
"birth_date": "2017-11-22 00:00:00",
"weight_chart": [],
"health_status": {
"id": 130,
"user_id": 258,
"weight": 95,
"height": 171,
},
我解碼了上面的json
$user = json_decode($response);
現在,我可以使用以下命令打印名字:$ user-> firstName
我的問題是:
您的json格式錯誤,請嘗試以下結構:
$str = '{
"firstName": "Jhon",
"lastName": "Doe",
"username": "jhon",
"avatar": "localhost/uploads/avatars/default.jpg",
"language": "ar",
"birth_date": "2017-11-22 00:00:00",
"weight_chart": [],
"health_status": {
"id": 130,
"user_id": 258,
"weight": 95,
"height": 171
}
}';
$obj = json_decode($str);
echo $obj->firstName.' - ';
echo $obj->health_status->id.' - ';
echo $obj->health_status->weight;
回應: Jhon - 130 - 95
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.