[英]As I read this Json in php?
我正在開始了解php,我很難在json中讀取此數組,我可以讀取所有信息,但無法從geofences數組中讀取數據
如何讀取“ geoFences” ID和名稱中包含的信息? 我的JSON示例
我需要在php json中閱讀此內容。
$response =
[
{
"id":441818,
"device":{
"id":6,
"uniqueId":"35390906000",
"name":"440",
"description":"COOR",
"timeout":3000,
"idleSpeedThreshold":0.0,
"iconType":{
"OFFLINE":{
"width":21,
"height":25,
"urls":[
"/img/marker-white.png",
"http://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/img/marker-green.png"
]
},
"LATEST":{
"width":21,
"height":25,
"urls":[
"http://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/img/marker.png",
"http://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/img/marker-green.png"
]
}
}
},
"time":"Fri, 07 Aug 2015 23:13:06 -0300",
"valid":true,
"latitude":-23.1,
"longitude":-46.1,
"altitude":745.0,
"speed":0.0,
"course":0.0,
"other":"\u003cinfo\u003e\u003cbattery\u003e58\u003c/battery\u003e\u003cip\u003e179.95.37.54\u003c/ip\u003e\u003c/info\u003e",
"geoFences":[
{
"id":16,
"name":"PL Eldorado",
"color":"20B2AA"
}
]
}
]
我需要在php中閱讀此信息...
"id":16,
"name":"PL Eldorado".
例如,如果我需要讀取設備->名稱,我可以這樣做:
$json=json_decode($response, true);
foreach ($json as $person_name => $person)
{
echo $person['device']['name'];
}
但是我做到了,不起作用。
$json=json_decode($response, true);
foreach ($json as $person_name => $person)
{
echo $person['geoFences']['id'];
echo $person['geoFences']['name'];
}
您在geoFences下有另一個數組。 這是循環:
foreach($json as $person){
foreach($person['geoFences'] as $g){
echo $g['id'].'<br>';
echo $g['name'].'<br>';
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.