1

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?

Nidheesh
  • 4,390
  • 29
  • 87
  • 150
  • http://www.json.org/javadoc/org/json/JSONArray.html – Rafael Nov 30 '14 at 02:54
  • From my earlier experience, do not just post the link. Think about the case where the link might be broken in future. Please write some explanation and address the link for more info. – Vamshi Suram Nov 30 '14 at 03:02

2 Answers2

3

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

Then use HTTPService instead: HTTPService AsyncToken and AsyncResponder example

Community
  • 1
  • 1
Clintm
  • 4,505
  • 3
  • 41
  • 54
1

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");
Brian
  • 3,850
  • 3
  • 21
  • 37