Java Equivilent of a PHP Array
<p>I need to send an array to a server but I cannot seem to find the correct formatting for it.</p>

<p>Here is the php equivalent that I need to send</p>

<pre><code>array(
      'interest' =&gt; 1,
      'charity' =&gt; 590,
      'items' =&gt; array(
        array(
          'cart_item_id' =&gt; 11197,
          'message' =&gt; '',
          'aid' =&gt; 174
        ),
      ),
    );
</code></pre>

<p>I am trying to get send my data in nameValuePairs - here is what I am trying</p>

<pre><code>List&lt;NameValuePair&gt; nameValuePairs  =   new ArrayList&lt;NameValuePair&gt;();
    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 &lt; 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)));
    }
</code></pre>

<p>This is incorrect tho. As always any help is much appreciated</p>

<p>Edit</p>

<p>For clarification this is what my app sends to the server</p>

<pre><code>[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]
</code></pre>

<p>but that is incorrect</p>
