1

In my Android application, I need to send following JSON array to server using name value pair. This is the following json response and I need to send insertedIDs array to the sever.

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

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

this is the following code to communicate to server.

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();
}
11
  • why not generating also a json and send it to the server? Have a look at gson (its a good json lib and many tutorials out there) Commented Dec 19, 2013 at 13:45
  • and what is your question? Commented Dec 19, 2013 at 13:48
  • 1
    @A.S.: OK, maybe I was too fast. @ murali_ma: do you also develop the server side part of this communication or can you talk to the people doing it? Commented Dec 19, 2013 at 13:55
  • 1
    murali_ma, generally, this is possible. But how to do it exactly depends on the people developing the server side. You need to negotiate that with them. If they can't tell how, then ask them to give you a working example. Otherwise, you can propose them solutions like A.S.'s with JSON or the one here with "[i]" in the keys: stackoverflow.com/questions/12365832/… . I think A.S.'s suggestion is best. Commented Dec 19, 2013 at 14:07
  • 1
    @murali_ma choose POST variables or JSON data but don't mix the 2! Commented Dec 19, 2013 at 14:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.