我想打印“0”和“1”的值以打印在 php 頁面上。為了做到這一點,我想知道如何以數組的形式訪問這個 json 對象。我已經解碼了。但仍然無法打印。 { "statusCode": 200, "message": "Data Received", "0": { "id": "385", "fname": "arriet ", "lname": "ephania ", "email": "[email protected]", "mob": "9877" }, "1": { "id": "386", "fname": "Kelly ", "lname": "Echo ", "email": "[email protected]", "mob": "1111" } }
2 回答

慕慕森
TA貢獻1856條經驗 獲得超17個贊
您需要使用帶有 true 標志的 json_decode 將其轉換為數組,然后讓每個數組循環遍歷其中的數據,
$arr = json_decode('
{
"statusCode": 200,
"message": "Data Received",
"0": {
"id": "385",
"fname": "arriet ",
"lname": "ephania ",
"email": "[email protected]",
"mob": "9877"
},
"1": {
"id": "386",
"fname": "Kelly ",
"lname": "Echo ",
"email": "[email protected]",
"mob": "1111"
}
}
', true);
foreach ($arr as $key => $value) {
// strict type check for key with integer values.
if(intval($key) === $key){
print_r($value);
}
}
- 2 回答
- 0 關注
- 141 瀏覽
添加回答
舉報
0/150
提交
取消