Android uploads array parameters to the PHP background.

Source: Internet
Author: User
: This article mainly introduces the problem of passing the array type parameters from Android to the PHP background. if you are interested in the PHP Tutorial, refer to it. During project development, the checkbox data in the forms submitted by the web to the background is transmitted in the form of arrays. However, when the mobile terminal wants to use the same interface to transmit data to the background, you will encounter the following problems:

1. how can I put an array in the RequestParams object to be accepted by the background?

Solution

for (int i = 0; i < array.size(); i++) {params.put("content["+i+"]", array.get(i));}

Create a number in a loop. Note that content ["+ I +"] is a String array when the content parameter is obtained in the PHP background.

2. the array is transmitted to the background, but the array may be out of order. you must note that it does not occur during testing in time because the map structure used by parameters in RequestParams is saved, map traversal is out of order,

The solution is to override the RequestParams class.

public  class MyRequestParams extends RequestParams{/** *  */private static final long serialVersionUID = 1L;private ArrayList
 
   list =null;public MyRequestParams() {list =new ArrayList
  
   ();}@Overridepublic void put(String key, String value) {list.add(new BasicNameValuePair(key, value));}@Overridepublic void put(String key, int value) {list.add(new BasicNameValuePair(key, String.valueOf(value)));}@Overridepublic void put(String key, long value) {list.add(new BasicNameValuePair(key, String.valueOf(value)));}@Overrideprotected ArrayList
   
     getParamsList() {return list ;}}
   
  
 

The above describes the problem of passing array-type parameters from Android to the PHP background, including some content. I hope my friends who are interested in the PHP Tutorial will be helpful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.