以下数据块是由网页与其他html数据一起产生的;
UIbuttons
如何从该字符串中提取多个变量,例如“ id”,“ rating”等数据,以便能够将其打印在另一个php页面上?
答案 0 :(得分:0)
您可以使用json_decode
将JSON转换为数组,然后遍历数组
$json = '{
"search":
{
"searchResults":
{
"results":[
{"id":"123","name":"ABC","rating":{"average":0,"count":2,"__typename":"Rating"},"category":"AAA/Cars","__typename":"ProductQuery"},
{"id":"456","name":"DEF","rating":{"average":5,"count":8,"__typename":"Rating"},"category":"BBB/Bikes","__typename":"ProductQuery"}
]
}
}
}';
$jsonToArray = json_decode($json,true);
foreach($jsonToArray['search']['searchResults']['results'] as $v){
echo $v['id'];
print_r($v['rating']);echo '<br/>';
}