在我的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();
}