Anil M
Anil M

Reputation: 1307

Send arraylist as request parameter through android

Is there any alternative to send request parameters through android other than NameValuePair. I'm trying to send arraylist as request parameter, but NameValuePair accepts only string value.

Upvotes: 2

Views: 2894

Answers (3)

Adi
Adi

Reputation: 13

Store arraylist in to a string and then send it..

ArrayList<String> contactlist=new ArrayList<String>();
        contactlist.add("Android");
        contactlist.add("tarnaka");
        contactlist.add("uppal");
        contactlist.add("Prasad");

        String[] contact=new String[contactlist.size()];
        contact=contactlist.toArray(contact);

Upvotes: 0

NeuraCache
NeuraCache

Reputation: 14174

read about JSONObject, JSONArray .. you can convert it to string with toString method and then bring it back to JSONObject, JSONArray passing this String constructor if you receive it from server.

Generally its a standard way of passing complex structures.

Upvotes: 0

appsroxcom
appsroxcom

Reputation: 2821

You may consider sending the ArrayList as JSONArray.

Check this SO post.

convert ArrayList<MyCustomClass> to JSONArray

Convert normal Java Array or ArrayList to Json Array in android

Upvotes: 2

Related Questions