Skip to content Skip to sidebar Skip to footer

Passing Arraylist To Php Using Android Asynchronous Http Client Issue

Im trying to send ArrayList to PHP ($_POST) and use it as an array. I use Android Asynchronous Http Client http://loopj.com/android-async-http/ My code ArrayList arr

Solution 1:

If you want to get all values write:

RequestParams params = new RequestParams();
params.put("descr_array_1", array.get(0) );
params.put("descr_array_2", array.get(1) );
params.put("descr_array_2", array.get(2) );

But I prefer you to use Gson to convert Array to String and use one pair only:

Gson gson = new Gson(); 
String out = gson.toJson(array);
params.put("descr_array", out ); 

Solution 2:

This is what worked for me:

RequestParamsparams=newRequestParams();

for (String val : array) {
    params.add("descr_array[]", val);
}

It doesn't require you to add extra Headers or import other libraries and works for both JSON and XML.


The important thing to note here is the use of add instead of put. See the difference between the two.

Solution 3:

This worked for me...

Map<String, String> aMap = newHashMap<String, String>();
aMap.put("f_name" ,"");
aMap.put("l_name" ,"");
aMap.put("email" ,edtEmail.getText().toString());
RequestParams params = newRequestParams();
params.put("user",aMap);

AsyncHttpClient client = newAsyncHttpClient();
client.post(url, params, n.....

Post a Comment for "Passing Arraylist To Php Using Android Asynchronous Http Client Issue"