Problem with Android passing array type parameters to PHP background

WBOY
Release: 2016-07-29 09:12:40
Original
1165 people have browsed it

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>
Copy after login

Use a loop to form numbers, pay attention to content["+i+"] In this way, when the content parameter is taken in the PHP background, it is a String type array

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template