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
Apache Flex

Avatar of undefined
Last Comment
andre72
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
Avatar of deepanjandas
deepanjandas
Flag of India image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of andre72
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?
Avatar of deepanjandas
deepanjandas
Flag of India image

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
andre72

ASKER

Thanks for your support
Apache Flex
Apache Flex

Apache Flex is a highly productive, open source application framework for building and maintaining expressive web applications that deploy consistently on all major browsers, desktops and devices (including smartphones, tablets and television). It provides a modern, standards-based language and programming model that supports common design patterns suitable for developers from many backgrounds. Flex applications can be deployed to the Adobe Player in the browser, Adobe AIR on desktop and mobile devices or to native Android, iOS, Windows or Mac applications.

4K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo