我想打印“0”和“1”的值以打印在 php 页面上。为了做到这一点,我想知道如何以数组的形式访问这个 json 对象。我已经解码了。但仍然无法打印。 { "statusCode": 200, "message": "Data Received", "0": { "id": "385", "fname": "arriet ", "lname": "ephania ", "email": "amym@mator.com", "mob": "9877" }, "1": { "id": "386", "fname": "Kelly ", "lname": "Echo ", "email": "sacen@mailinator.com", "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": "amym@mator.com",
"mob": "9877"
},
"1": {
"id": "386",
"fname": "Kelly ",
"lname": "Echo ",
"email": "sacen@mailinator.com",
"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 关注
- 110 浏览
添加回答
举报
0/150
提交
取消