这是一个有效的 json 和从中生成的数组。像对待 PHP 数组一样对待它。
<?php
$json = <<<JSON
{
"members": [
{
"member": {
"id": 464258,
"display_name": "test1",
"mitch_rank_index": 6.64,
"distance": 0.56009166639932,
"unread_messages_from": 0,
"explorer": false,
"online": true,
"favourite": false,
"fan": false,
"thumbnail_url": "link",
"profile_photo_url": "link"
}
},
{
"member": {
"id": 1009345,
"display_name": "Test2",
"mitch_rank_index": 6.32,
"distance": 0.583112841628013,
"unread_messages_from": 0,
"explorer": false,
"online": false,
"favourite": false,
"fan": false,
"thumbnail_url": "link",
"profile_photo_url": "Link"
}
},
{
"member": {
"id": 1052568,
"display_name": null,
"mitch_rank_index": 5.699999999999999,
"distance": 0.597684462292014,
"unread_messages_from": 0,
"explorer": false,
"online": true,
"favourite": false,
"fan": false,
"thumbnail_url": "link",
"profile_photo_url": "link"
}
}
]
}
JSON;
$json = json_decode($json,true);
print("<pre>");
print_r($json);
print("</pre>");
?>
更新
要显示 JSON 中的所有 ID,您可以从以下代码中获取示例
// $ids will contain array of all ID that ara available in JSON
foreach ($json['members'] as $members) $ids[] = $members['member']['id'];
// you can use $ids array from now
// following code just shows how array can look like in php
print("<pre>");
print_r($ids);
print("</pre>");
// use foreach to go through all IDs and do something for each of them
// this code simply goes through all IDs and prints each of them on screen
// again, this is a way to manipulate through all IDS from your JSON
foreach ($ids as $id)
{
// you can use $id here in this loop
print("id: ".$id."<br />");
}