0

我无法解析这个json:

var _json =   [{"place_id":"18094048","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"1695627257","boundingbox":[34.549406280518,34.569410095215,135.45611022949,135.47612548828],"lat":"34.5594098","lon":"135.4661246","display_name":"Singapore Embassy, \u583a\u72ed\u5c71\u7dda (Sakai-Sayama line), Sakai, Senboku District, Kinki Region, Giappone","class":"amenity","type":"embassy"},

"place_id":"17954461","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"1695740584","boundingbox":

[35.647695770264,35.667699584961,139.72419189453,139.74420715332],"lat":"35.6576973","lon":"139.7341957","display_name":"Singapore Embassy, Gaien higashi dori, Roppongi, Minato, \u5317\u8db3\u7acb\u90e1, 1080074, Giappone","class":"amenity","type":"embassy"}]

我正在尝试JSON.parse(_json); 它在控制台中返回:SyntaxError:JSON.parse:意外字符

console.log(JSON.parse(_json));

我需要纬度和经度值。

4

2 回答 2

3

好吧,这不是一个 json 字符串

它只是一个带有对象的 JS 数组

您可以像这样简单地使用它:

for(var i = 0 ; i < _json.length ; i++ ){
   var jsonObject  = _json[i];

   // then just use jsonObject['lat'] , jsonObject['license'] .....etc
}
于 2012-10-07T11:35:00.067 回答
1

你 var_json不是JSON:它是一个标准的 javascript 数组,你可以在不解析的情况下使用。

如果您想要第一个纬度,只需执行

var lat = _json[0].lat;

但我建议给出一个比 更好的名称_json,例如places这个数组包含地点。

var firstPlace = _json[0]; // firstPlace has properties named lat and lon
于 2012-10-07T11:30:56.717 回答