Nidheesh
Nidheesh

Reputation: 4562

Pass an array collection in JSON

I am trying to pass an array collection from flex page to my backend java.Here is the code,

private function getItems():void{

                myObj  = new Object();
                myObj['dId']= dId.value.toString();
                myObj['itmList']=JSON.encode(itmList);// trying to pass like this..
                var url:String = URLManager.baseURL;
                    url = url+"myController/ReportController?do=getItems";
                    url = url+"&parameter="+ escape(JSON.encode(myObj))
                    var urlRequest:URLRequest = new URLRequest(url);
                    navigateToURL(urlRequest,"_blank");

               }

My itmList is an array collection, how can I pass it from JSon to Java controller? And how to get that in Java?

Upvotes: 1

Views: 292

Answers (2)

Brian
Brian

Reputation: 3914

Another option is to use JSON.stringify instead (Flash has had native JSON support since FP 11). Just make sure you remove the import com.adobe.serialization.json.JSON; from the top of your file.

myObj['itmList']=JSON.stringify(itmList);

Or, since you're encoding your whole data object,

myObj['itmList']=itmList.source;

var url:String = URLManager.baseURL;
                url = url+"myController/ReportController?do=getItems";
                url = url+"&parameter="+ escape(JSON.stringify(myObj))
                var urlRequest:URLRequest = new URLRequest(url);
                navigateToURL(urlRequest,"_blank");

Upvotes: 1

Clintm
Clintm

Reputation: 4877

JSON.encode the itmList source array instead. (i.e. itmList.source is an array)

Then use HTTPService instead: HTTPService AsyncToken and AsyncResponder example

Upvotes: 3

Related Questions