JSON 语法问题
Issue with JSON syntax
我对JSON不太熟悉,主要是PHP。当我 运行 查询 Mapquest 地理编码 API 时,我得到以下 json 字符串,在 PHP 中尝试 json_decode 它变成 "NULL" ].
renderOptions({
"info": {
"statuscode": 0,
"copyright": {
"text": "\u00A9 2016 MapQuest, Inc.",
"imageUrl": "https://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "\u00A9 2016 MapQuest, Inc."
},
"messages": []
},
"options": {
"maxResults": -1,
"thumbMaps": true,
"ignoreLatLngInput": false
},
"results": [{
"providedLocation": {
"street": "Kingston Upon Thames,uk"
},
"locations": [{
"street": "",
"unknownInput": "",
"type": "s",
"latLng": {
"lat": 51.409628,
"lng": -0.306262
},
"displayLatLng": {
"lat": 51.409628,
"lng": -0.306262
},
"mapUrl": "https://open.mapquestapi.com/staticmap/v4/getmap?key=na&type=map&size=225,160&pois=purple-1,51.4096275,-0.3062621,0,0,|¢er=51.4096275,-0.3062621&zoom=12&rand=54353"
}]
}]
})
运行 通过 JSONLint,我得到以下错误:
Error: Parse error on line 1: renderOptions({ "in ^ Expecting
'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
我认为修复非常简单,但我不太了解 JSON 语法,所以我一直在摸索着把东西放在 'renderOptions'.[=13= 之前]
解决问题的正确语法是什么?
这将是一个有效的 json
{
"renderOptions": {
"info": {
"statuscode": 0,
"copyright": {
"text": "\u00A9 2016 MapQuest, Inc.",
"imageUrl": "https://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "\u00A9 2016 MapQuest, Inc."
},
"messages": []
},
"options": {
"maxResults": -1,
"thumbMaps": true,
"ignoreLatLngInput": false
},
"results": [{
"providedLocation": {
"street": "Kingston Upon Thames,uk"
},
"locations": [{
"street": "",
"unknownInput": "",
"type": "s",
"latLng": {
"lat": 51.409628,
"lng": -0.306262
},
"displayLatLng": {
"lat": 51.409628,
"lng": -0.306262
},
"mapUrl": "https://open.mapquestapi.com/staticmap/v4/getmap?key=na&type=map&size=225,160&pois=purple-1,51.4096275,-0.3062621,0,0,|¢er=51.4096275,-0.3062621&zoom=12&rand=54353"
}]
}]
}
}
删除 renderOptions(),括号内的内容是 JSON,从第一个卷曲开始到最后一个卷曲结束。
在您的 URL 到 mapquest 地理编码服务中,您将有一个参数 "callback=renderOptions" - 可能是从示例中复制和粘贴的。删除该参数以删除回调包装。
我对JSON不太熟悉,主要是PHP。当我 运行 查询 Mapquest 地理编码 API 时,我得到以下 json 字符串,在 PHP 中尝试 json_decode 它变成 "NULL" ].
renderOptions({
"info": {
"statuscode": 0,
"copyright": {
"text": "\u00A9 2016 MapQuest, Inc.",
"imageUrl": "https://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "\u00A9 2016 MapQuest, Inc."
},
"messages": []
},
"options": {
"maxResults": -1,
"thumbMaps": true,
"ignoreLatLngInput": false
},
"results": [{
"providedLocation": {
"street": "Kingston Upon Thames,uk"
},
"locations": [{
"street": "",
"unknownInput": "",
"type": "s",
"latLng": {
"lat": 51.409628,
"lng": -0.306262
},
"displayLatLng": {
"lat": 51.409628,
"lng": -0.306262
},
"mapUrl": "https://open.mapquestapi.com/staticmap/v4/getmap?key=na&type=map&size=225,160&pois=purple-1,51.4096275,-0.3062621,0,0,|¢er=51.4096275,-0.3062621&zoom=12&rand=54353"
}]
}]
})
运行 通过 JSONLint,我得到以下错误:
Error: Parse error on line 1: renderOptions({ "in ^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
我认为修复非常简单,但我不太了解 JSON 语法,所以我一直在摸索着把东西放在 'renderOptions'.[=13= 之前]
解决问题的正确语法是什么?
这将是一个有效的 json
{
"renderOptions": {
"info": {
"statuscode": 0,
"copyright": {
"text": "\u00A9 2016 MapQuest, Inc.",
"imageUrl": "https://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "\u00A9 2016 MapQuest, Inc."
},
"messages": []
},
"options": {
"maxResults": -1,
"thumbMaps": true,
"ignoreLatLngInput": false
},
"results": [{
"providedLocation": {
"street": "Kingston Upon Thames,uk"
},
"locations": [{
"street": "",
"unknownInput": "",
"type": "s",
"latLng": {
"lat": 51.409628,
"lng": -0.306262
},
"displayLatLng": {
"lat": 51.409628,
"lng": -0.306262
},
"mapUrl": "https://open.mapquestapi.com/staticmap/v4/getmap?key=na&type=map&size=225,160&pois=purple-1,51.4096275,-0.3062621,0,0,|¢er=51.4096275,-0.3062621&zoom=12&rand=54353"
}]
}]
}
}
删除 renderOptions(),括号内的内容是 JSON,从第一个卷曲开始到最后一个卷曲结束。
在您的 URL 到 mapquest 地理编码服务中,您将有一个参数 "callback=renderOptions" - 可能是从示例中复制和粘贴的。删除该参数以删除回调包装。