有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在安卓中使用名称-值对向服务器发送数组

在我的Android应用程序中,我需要使用名称-值对将以下JSON数组发送到服务器。这是下面的json响应,我需要向服务器发送insertedIDs数组

{
    "message": "Deal was successfully done",
    "insertedIDs": [
        {
            "deal_id": "579",
             "name": "zzzz"

        },
        {
            "deal_id": "580",
             "name": "zzzz"
        }
    ],
    "status": "1"
}

以下是与服务器通信的代码

httpClient = new DefaultHttpClient();
resHandler = new BasicResponseHandler();
httpPost = new HttpPost(payment);
nameValuePairs = new ArrayList<NameValuePair>(4);

nameValuePairs.add(new BasicNameValuePair("loggedin_id",loggedin_id));
nameValuePairs.add(new BasicNameValuePair("amount",amount));
nameValuePairs.add(new BasicNameValuePair("payment_card_id",id));
nameValuePairs.add(new BasicNameValuePair("insertedIDs", ????)); // need to add the json array here.

try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    jsonResponse = httpClient.execute(httpPost, resHandler);
    Log.e("payment response", jsonResponse);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

共 (0) 个答案