我需要發送一個數組到一個服務器,但我似乎無法找到正確的格式。一個PHP數組的Java Equivilent
這裏是PHP的等價,我需要發送
array(
'interest' => 1,
'charity' => 590,
'items' => array(
array(
'cart_item_id' => 11197,
'message' => '',
'aid' => 174
),
),
);
我試圖讓namevaluepairs中把我的數據 - 這裏就是我想
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)));
}
這是不正確壽。一如往常的任何幫助深表感謝
編輯
爲了澄清這是我的應用程序向服務器發送
[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]
但是這是不正確
的想法,我想你在for循環中,首先檢查名稱和值正確的按照你祝使用System.out.prinln創建問題() ;,請注意,您必須將字符串值發送到服務器 – 2012-01-10 14:28:22
該應用運行正常。它將詳細信息發送到服務器,但它們的格式不正確。我發送字符串 – jiduvah 2012-01-10 14:31:45