JSON in Action Script: how to get the properties and values on a JSON object? JSON in Action Script: how to get the properties and values on a JSON object? json json

JSON in Action Script: how to get the properties and values on a JSON object?


First of all you need to decode the JSON, probably using as3corelib:

var jsonString:String = '{"srcLocation":"pc","filename":"name","fileext":"jpg","url":""}';var decodedObj:Object = JSON.decode(jsonString);

Then all you have to do is loop through the object to get all the name/value pairs:

for(var key:String in decodedObj) {    trace("Name: " + key + " - Value: " + decodedObj[key];}

Which will output:

Name: srcLocation - Value: pcName: filename - Value: nameName: fileext - Value: jpgName: url - Value:


First you should load the JSON file using URLLoader and then decode the data into Objectand after that you will be able to get the corresponding value of the properties of thatObject:

        var myRequest:URLRequest = new URLRequest("Your JSON file Name");        var myLoader = new URLLoader();        myLoader.addEventListener(Event.COMPLETE, onload);        myLoader.load(myRequest);        function onload(evt:Event):void        {            var myData:Object = JSON.decode(myLoader.data);            trace(myData.firstName);            trace(myData.job);            trace(myData.age);                      }

for any further help go through this link:http://swati61.blogspot.com/2011/06/json-and-as3-communication.html


I suggest you use Adobe's Native JSON decoding.