Php JSON多级解析
如何从下面的JSON获取文本 JSON数据 需要得到“Testing”、“Testing2”等多层次的JSON风格。最简单的方法是什么Php JSON多级解析,php,Php,如何从下面的JSON获取文本 JSON数据 需要得到“Testing”、“Testing2”等多层次的JSON风格。最简单的方法是什么 foreach ($response->data as $res) { echo $res['comments']; } 使用json_decode() $test_json=' { "media": { "data": [ { "comments":
foreach ($response->data as $res) {
echo $res['comments'];
}
使用json_decode()
$test_json='
{ "media":
{ "data":
[
{ "comments":
{ "data":
[
{ "text": "Testing", "id": "17935572247064063" },
{ "text": "Testing2", "id": "17909467621160083" },
{ "text": "Testing3", "id": "17879193508206704" },
{ "text": "Testing4", "id": "17936230114007492" },
{ "text": "Testing5", "id": "17861359981236880" },
{ "text": "Testing6", "id": "17932586956016890" },
{ "text": "Testing7", "id": "17920569544116678" },
{ "text": "Testing8", "id": "17933592700059204" }
]
}
}
]
}
}
';
$test_json=json_decode($test_json,true);
foreach($test_json['media']['data'][0]['comments']['data'] as $row){
print_r($row['text']);
}
试一试
您的文档中没有
测试1
,您指的是前两个估价师,测试等吗
$responseData = json_decode($response->data, true);
$result = $responseData['media']['data'][0]['comments']['data'];
foreach($result as $data) {
// do your stuff here
}