我一直在尝试和搜索,但没有成功。我尝试解析以下json字符串:
{“label”:“我的ncWMS服务器”,“孩子”:[{“label”:“冠军”,“孩子”:{“id”:“冠军/XE”,“标签”:“sea_surface_height_above_geoid”},{“id”:“冠军/U”,"label":"barotropic_eastward_sea_water_velocity"},{“id”:“冠军/V”,"label":"barotropic_northward_sea_water_velocity"},{“id”:“冠军/UZ”,"label":"eastward_sea_water_velocity"},{“id”:“冠军/VZ”,"label":"northward_sea_water_velocity"},{“id”:“冠军/SAL”,"label":"sea_water_salinity"},{“id”:“冠军/临时”,"label":"sea_water_temperature"},{“id”:“冠军/H0”,"label":"sea_floor_depth_below_geoid"},{“id”:“冠军/HX”,"label":"sea_floor_depth_below_geoid_u_location"},{“id”:“冠军/HY”,"label":"sea_floor_depth_below_geoid_v_location"},{“id”:“冠军/正压_海_水_速度”,"label":"barotropic_sea_water_velocity"},{“id”:“冠军/海_水_速度”,“标签”:“sea_water_velocity”}]}
但是从字符串json解码得到的对象总是空的: var parsed:Object=JSON.decode(event.result as as3 ) as Object;
有人能给我点提示吗?
非常感谢!G
发布于 2010-10-06 01:35:53
使用这个验证器:http://jsonformatter.curiousconcept.com/,它说末尾有一个额外的]}。
发布于 2010-10-06 21:02:12
确实,我的复制粘贴失败了。但是使用正确的json字符串,我仍然会遇到错误。成功之道:
public function onResultLoadFiles(event:ResultEvent):void{
var jsonString:String = StringUtil.trim(String(event.result));
if ((String(event.result) != null) && (String(event.result) != "")) {
var j:Object = JSON.decode(jsonString);
var server_label:String = j.label;
}
trace(server_label)
}https://stackoverflow.com/questions/3866052
复制相似问题