我对编码非常陌生。我在网上看了很多例子,但似乎找不到我想要的东西。
https://data.calgary.ca/resource/k7p9-kppz.json
返回的JSON:
[
{
":@computed_region_4a3i_ccfj": "1",
":@computed_region_4b54_tmc4": "8",
":@computed_region_kxmf_bzkv": "29",
":@computed_region_p8tp_5dkv": "5",
"description": "Glenmore Trail / 14 Street SW (West)",
"latitude": "50.9938095441965",
"location": {
"latitude": "50.9938095441965",
"longitude": "-114.094978074903",
"human_address": "{\"address\": \"\", \"city\": \"\", \"state\": \"\", \"zip\": \"\"}"
},
"longitude": "-114.094978074903",
"quadrant": "SW",
"url": {
"url": "http://trafficcam.calgary.ca/loc111.jpg"
}
},
{
":@computed_region_4a3i_ccfj": "2",
":@computed_region_4b54_tmc4": "7",
":@computed_region_kxmf_bzkv": "62",
":@computed_region_p8tp_5dkv": "7",
"description": "Memorial Drive / 9 Street NW",
"latitude": "51.0536259017801",
"location": {
"latitude": "51.0536259017801",
"longitude": "-114.081180764729",
"human_address": "{\"address\": \"\", \"city\": \"\", \"state\": \"\", \"zip\": \"\"}"
},
"longitude": "-114.081180764729",
"quadrant": "NW",
"url": {
"url": "http://trafficcam.calgary.ca/loc59.jpg"
}
},
我正在尝试获取description
和url
。
我获取description
没问题,但是当我尝试获取url
时,会抛出错误。
答案 0 :(得分:1)
尝试将json_decode();
和true
用作second
参数,如果将true
添加为第二个参数,则可以得到关联数组[array of array] else array of对象
$jsonToarray = json_decode($jsonData,true);// it will return array of array with assosiative format
并获得url
echo $jsonToarray['url']['url'];die;
您可以直接使用
description
,因为它不是嵌套的,但是url
是嵌套的数组,因此它们之间是有区别的