Link to home
Start Free TrialLog in
Avatar of andre72
andre72

asked on

How to use JSONDecoder ?

Hi,

I like to decode a JSON string with Flash Builder 4.
So I include com.adobe.serializers.json but can't find any methode there for.

Can somebody show me how to use JSONDecoder please?

Thanks

Andre
Avatar of deepanjandas
deepanjandas
Flag of India image

//sample json data passed - [ {"name":"Jaylo", "number":"3243251"}, {"name":"Jenny", "phone":"8675309"}])

var jsonData:String = "[ {"name":"Jaylo", "number":"3243251"}, {"name":"Jenny", "phone":"8675309"}])";

var data:Array= JSON.decode(loader.data) ;
trace(People[0].name) ; //Jaylo
trace(People[0].number) ; //3243251
trace(People[1].name) ; //Jenny
trace(People[1].number) ; //8675309

Here the object returned is an Array; it can also be object.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com
Sorry dude, I copied it wrong above.
//sample json data passed - [ {"name":"Jaylo", "number":"3243251"}, {"name":"Jenny", "phone":"8675309"}])

var jsonData:String = "[ {"name":"Jaylo", "number":"3243251"}, {"name":"Jenny", "phone":"8675309"}])";

var data:Array= JSON.decode(jsonData) ;

Also try using ObjectUtils.toString(data);
trace(data[0].name) ; //Jaylo
trace(data[0].number) ; //3243251
trace(data[1].name) ; //Jenny
trace(data[1].number) ; //8675309

Here the object returned is an Array; it can also be object.

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com
Avatar of andre72
andre72

ASKER

Yes I read some threads like this but I've no JSON.decode()

I thinks you use the workspace com.adobe.serialization but this one I've not available.
The one I found is called com.adobe.serializers and it doesn't contain decode() ...
ASKER CERTIFIED SOLUTION
Avatar of deepanjandas
deepanjandas
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andre72

ASKER

deepanjandas thank you very much.
Maybe you can also tell a novice in which directory to place it best and how to referer it than to my project - or will Flex recognize it by itself than?
Do you have a src folder, so just paste the com folder under src and you should be done.


Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com
Avatar of andre72

ASKER

Thanks for your support