views:

62

answers:

2

Hi,

I have been trying and searching with no success.I waned to parse the following json string :

{"label":"My ncWMS server","children":[{"label":"champ","children": [{"id":"champ/XE","label":"sea_surface_height_above_geoid"},{"id":"champ/U","label":"barotropic_eastward_sea_water_velocity"},{"id":"champ/V","label":"barotropic_northward_sea_water_velocity"},{"id":"champ/UZ","label":"eastward_sea_water_velocity"},{"id":"champ/VZ","label":"northward_sea_water_velocity"},{"id":"champ/SAL","label":"sea_water_salinity"},{"id":"champ/TEMP","label":"sea_water_temperature"},{"id":"champ/H0","label":"sea_floor_depth_below_geoid"},{"id":"champ/HX","label":"sea_floor_depth_below_geoid_u_location"},{"id":"champ/HY","label":"sea_floor_depth_below_geoid_v_location"},{"id":"champ/barotropic_sea_water_velocity","label":"barotropic_sea_water_velocity"},{"id":"champ/sea_water_velocity","label":"sea_water_velocity"}] }]}]}

but the object resulting from the as3 json decode i always null: var parsed:Object=JSON.decode(event.result as String) as Object;

Could someone give me a clue ?

Thanks so much ! G

+2  A: 

Using this validator: http://jsonformatter.curiousconcept.com/, it says there's an extra ]} on the end.

Anthony -GISCOE-
A: 

Yes indeed, my copy paste failed. But with an correct json string, I was still getting error. What worked :

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) 
}