以JSON格式解析数据

时间:2014-08-22 16:19:34

标签: jquery json

我有以下JSON lint所说的JSON字符串是有效的,但是,我有一段时间只是访问它的值。

var json='{"currentVersion":10.2,"folders":["Canvas","Demographics","Elevation","Ocean","Reference","Specialty","Utilities"],"services":[{"name":"ESRI_Imagery_World_2D","type":"MapServer"},{"name":"ESRI_StreetMap_World_2D","type":"MapServer"},{"name":"I3_Imagery_Prime_World","type":"GlobeServer"},{"name":"NASA_CloudCover_World","type":"GlobeServer"},{"name":"NatGeo_World_Map","type":"MapServer"},{"name":"NGS_Topo_US_2D","type":"MapServer"},{"name":"Ocean_Basemap","type":"MapServer"},{"name":"USA_Topo_Maps","type":"MapServer"},{"name":"World_Imagery","type":"MapServer"},{"name":"World_Physical_Map","type":"MapServer"},{"name":"World_Shaded_Relief","type":"MapServer"},{"name":"World_Street_Map","type":"MapServer"},{"name":"World_Terrain_Base","type":"MapServer"},{"name":"World_Topo_Map","type":"MapServer"}]}'

例如,如何访问currentVersion的值?

我尝试json.currentVersion但它返回{

1 个答案:

答案 0 :(得分:5)

作为一个JSON字符串,这是你所拥有的,你无法真正访问任何东西,你必须先解析它

var obj = JSON.parse(json);

obj.currentVersion