Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:40:34+00:00 2026-05-28T01:40:34+00:00

I need to send an array to a server but I cannot seem to

  • 0

I need to send an array to a server but I cannot seem to find the correct formatting for it.

Here is the php equivalent that I need to send

array(
      'interest' => 1,
      'charity' => 590,
      'items' => array(
        array(
          'cart_item_id' => 11197,
          'message' => '',
          'aid' => 174
        ),
      ),
    );

I am trying to get send my data in nameValuePairs – here is what I am trying

List<NameValuePair> nameValuePairs  =   new ArrayList<NameValuePair>();
    if (interest == true) {
        nameValuePairs.add(new BasicNameValuePair("interest", "1"));                
    } else {
        nameValuePairs.add(new BasicNameValuePair("interest", "0"));    
    }
    nameValuePairs.add(new BasicNameValuePair("charity", String.valueOf(charityId)));
    int len = cartItems.size();
    for (int i = 0; i < len; ++i) {
         nameValuePairs.add(new BasicNameValuePair("items[" + String.valueOf(i) + "]" + "[cart_item_id]", String.valueOf(cartItems.get(i).cartItemId)));
        nameValuePairs.add(new BasicNameValuePair("items[" + String.valueOf(i) + "]" + "[message]", cartItems.get(i).message));
        nameValuePairs.add(new BasicNameValuePair("items[" + String.valueOf(i) + "]" + "[aid]", String.valueOf(cartItems.get(i).addressId)));
    }

This is incorrect tho. As always any help is much appreciated

Edit

For clarification this is what my app sends to the server

[interest=0, charity=1878, items[0][cart_item_id]=14498, items[0][message]=, items[0][aid]=315, items[1][cart_item_id]=14499, items[1][message]=, items[1][aid]=318]

but that is incorrect

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:40:35+00:00Added an answer on May 28, 2026 at 1:40 am

    use a HashMap<Object,Object> , and then when you want to add the sub array :

    array(
              'cart_item_id' => 11197,
              'message' => '',
              'aid' => 174
    )
    

    just add a new HashMap<String,String> into your Super HashMap<Object,Object> : the logic will be something like this:

    HashMap parentMap = new HashMap();
    HashMap subMap = new HashMap();

    // put params into parentMap
    parentMap.put("key1", "this is a string value");
    parentMap.put("key2", 45);
    parentMap.put("key3", new Date());
    
    subMap.put("card_item_id", ""+11197);
    subMap.put("message", "this is a message from subMap");
    parentMap.put("items", subMap);
    
    //get the subMap from the parentMap like this 
    HashMap<String, String> copySubMap = (HashMap<String, String>) parentMap.get("items");
    

    hope that you got the idea of how formatting your array 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to send an array of products by email with PHP but I'm
I have the need to send an array of ID's to my server-side in
I need to send byte[] array using WCF services and I care about message
I need send certain attributes(say, human readable user name) from server to client after
I need to send hundreds of newsletters, but would like to check first if
I need to send a very specific (non-standard) string to an FTP server: dir
I need to use HTTP Post to send a a string array like so...
Hi every one I need to send an array as the data of a
I have an array of hashes in Javascript, which I need to send as
A quick question. I need to submit an array of object to the server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.