Android to PHP background array type parameter-like problem

Source: Internet
Author: User
During the development of the project, the data of the checkbox in the form submitted to the background by the web is transmitted as an array, but we will encounter the following problems when we use the same interface to transmit data to the background on the mobile side .

1. How do I put an array in the Requestparams object to accept the background?

Workaround

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

use loops to assemble numbers, note content["+i+"] This is a string type array when PHP background takes the content parameter

2. The array is uploaded to the background but the array may appear disorderly sequence phenomenon, timely testing did not occur also need to pay attention to, this is because requestparams inside the map structure of the stored parameters, map traversal out is unordered,

The workaround 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 android to PHP background array types of parameters, including the contents of the content, I hope the PHP tutorial interested in a friend 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.