我知道我在这里遗漏了一些非常基本的东西:
我的json数据如下:
id: "123",
status: "SET",
sections: [
{
key: "top_details",
title: "top Details",
fields: [
{
key: "order_id",
value: "123456",
},
{
key: "tracking_id",
value: "98765",
}
id: "456",
status: "UNSET",
sections: [
{
key: "top_details",
title: "top Details",
fields: [
{
key: "order_id",
value: "55555",
},
{
key: "tracking_id",
value: "77777",
}
我可以使用
从顶层获取值foreach ($json as $key=>$value)
{
echo $value['id'];
echo $value['status'];
}
但我似乎无法弄清楚如何获取'order_id'和'tracking_id'下的嵌套值。
谢谢你,原谅我的无知。答案 0 :(得分:0)
应该这样做。
foreach ($json as $key=>$value)
{
foreach($json['sections'] as $sections){
foreach($sections['fields'] as $data){
echo $data['key']."=".$data["value"];
}
}
}