Search code examples
actionscript-3jsondataprovider

unable to decode JSON to dataprovider


I am loading a php file and calling this function decodeJSON want to parse the data and dispaly it into a combo box but when i do a trace all i get is

[object Object],[object Object],[object Object]

Here is the code

    function decodeJSON(event:Event):void{
var loader2:URLLoader = URLLoader(event.target);
var jsonArray:Array = JSON.decode(loader2.data) as Array; 
var dp:DataProvider = new DataProvider();
trace(jsonArray);
combo.dataProvider = dp;
for (var i=0; i<jsonArray.length; i++) 
{ 
dp.addItem({Label: "Name="+jsonArray[i].Name});
trace(jsonArray[i].Name);
}

Solution

  • so it looks like it has parsed just fine but if you want it to fully trace out you are going to need to loop through the objects as well. Trace will only print out the top level of the object you are tracing. In this case you have an array with 3 elements in it. If you want to test to see if it parsed it correctly try tracing out something that you know should be within the object like:

    trace(jsonArray[0].itemName)