문제

I have seen couple of examples which takes form data to php server, but I don't see any example for sending arrayList of values to php server. Could anyone help me out ? I know how to do this:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

I would like to do something like this :

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
nameValuePairs.add(new BasicNameValuePair("id", "12348"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "wassup"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

Plz help.

Thanks.

도움이 되었습니까?

해결책

You can do something like this :

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
nameValuePairs.add(new BasicNameValuePair("colours[]","red"));  
nameValuePairs.add(new BasicNameValuePair("colours[]","white"));  
nameValuePairs.add(new BasicNameValuePair("colours[]","black"));  
nameValuePairs.add(new BasicNameValuePair("colours[]","brown"));  

where colour is your array tag. Just user [] after your array tag and put value. Eg. if your array tag name is colour then use it like colour[] and put value in loop.

Here is the link : Orignal Question

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top