During the project development process, the checkbox data in the form submitted by the web to the background is transmitted in the form of an array. However, when we use the same interface on the mobile terminal to transmit data to the background, we will encounter the following situations: Questions
1. How to put an array in the RequestParams object so that the background can accept it?
Solution
<span style="font-size:24px;">for (int i = 0; i < array.size(); i++) { params.put("content["+i+"]", array.get(i)); }</span>
2. The array is passed In the background, the array may be out of order. You need to pay attention if it does not happen during testing. This is because the map structure used to store parameters in RequestParams is out of order when the map is traversed.
The solution is Override the RequestParams class
<span style="font-size:24px;">public class MyRequestParams extends RequestParams{ /** * */ private static final long serialVersionUID = 1L; private ArrayList<BasicNameValuePair> list =null; public MyRequestParams() { list =new ArrayList<BasicNameValuePair>(); } @Override public void put(String key, String value) { list.add(new BasicNameValuePair(key, value)); } @Override public void put(String key, int value) { list.add(new BasicNameValuePair(key, String.valueOf(value))); } @Override public void put(String key, long value) { list.add(new BasicNameValuePair(key, String.valueOf(value))); } @Override protected ArrayList<BasicNameValuePair> getParamsList() { return list ; } }</span>
The above introduces the problem of Android transmitting array type parameters to the PHP background, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.