user345824
user345824

Reputation:

How to convert a json array into a flex 4 array (as3)?

friends... my json array is

{"result":[{"status":0,"statusmsg":"Sorry, that's an invalid domain\n","rawout":null,"options":null}]}

how to convert this a json array into a flex 4 array (as3)?

Thanks for all help's

Upvotes: 3

Views: 9471

Answers (3)

user747344
user747344

Reputation: 179

Here is a simpler way using flex 4.5 internal library (haven't test with flex 4)

import com.adobe.serializers.json.JSONDecoder;
var j:JSONDecoder= new JSONDecoder();   
var obj:Object= j.decode(json string);
myarray= obj as ArrayCollection;

Upvotes: 0

cabaji99
cabaji99

Reputation: 1445

i found a way to send json through javascript, el, in a jsf page, first i enconde the the arraylist of objects with the flexjson library in java.

2) the this object i put it in a java bean 3) the i call the javascript with the oncomplete event 4) like this callapp(#{bean.jsonString}) 5) this is received in flex with the external interface ExternalInterface.addCallback

http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7e92.html

6) then something weird occurs, the json string is converted in a array of objects of ACTIONSCRIPT so i just have to loop through the array, and obtain the objects properties and buala …

Upvotes: 0

PatrickS
PatrickS

Reputation: 9572

You will need to download the as3corelib library and add it to your Library path
https://github.com/mikechambers/as3corelib

You can then use the JSON decode method which will return an Object.

    var object:Object = JSON.decode( jsonString );

but you should be able to coerce your Object into an Array

    var array:Array = object as Array;

if for some reason, this doesn't work, you could try

    var array:Array = [];
    for( var prop:String in obj )
        array.push( obj[prop] );

Upvotes: 7

Related Questions