I want to make a nested nameValuePairs 开发者_运维百科something like this:
List nameValuePairs = new ArrayList(1);
nameValuePairs.add(new BasicNameValuePair("key", new BasicNameValuePair("key2", "value").toString() ) );
I know this doesn't work, but what should I do to get this nesting right?
I solved it!
the trick was to do it like this:
nameValuePairs.add(new BasicNameValuePair("[key][key2]", "value"));
Create json objects, and you can add json object inside json object with name value pair
JSONObject jsonParam1 = new JSONObject();
JSONObject jsonParam2 = new JSONObject();
JSONObject jsonParam3 = new JSONObject();jsonParam1.put("action", "add"); // add data to json object (name value pair)
jsonParam1.put("first_name", "sam");
jsonParam1.put("last_name", "sam pasas");
jsonParam2.put("gender", "M");
jsonParam2.put("dob", "12-12-2015");
jsonParam2.put("street_address1", "sdfsdf");//add json object inside json object (namevaluepair)
jsonParam3.put("details1",jsonParam1);
jsonParam3.put("details2",jsonParam2); `
精彩评论