combine two Map String into JSON
Here is JSON String what I expected:
{
"startDate": "2013-01-01",
"columns": "mode , event",
"endDate": "2013-02-01",
"selection": {
"selectionMatch": "123456789012",
"selectionType": "smart"
}
}
And Here is the JAVA codes, but I didn't make it successful:
public static String BuildJson() throws JSONException{
Map<String, String> map1 = new HashMap<String, String>();
map1.put("startDate", "2013-01-01");
map1.put("endDate", "2013-02-01");
map1.put("columns", "mode , event");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("selectionType", "smart");
map2.put("selectionMatch", "123456789012");
JSONArray ja2 = new JSONArray();
ja2.put(map2);
System.out.println(ja2.toString());
map1.put("selection", ja2.toString());
System.out.println();
JSONArray ja = new JSONArray();
ja.put(map1);
System.out.println(ja.toString());
return null;
}
The challenge is how to combine the two map string that are not at the
same level. My code result is :
[{"startDate":"2013-01-01","columns":"mode ,
event","endDate":"2013-02-01","selection":"[{\"selectionMatch\":\"123456789012\",\"selectionType\":\"smart\"}]"}]
Can someone help me with it?
No comments:
Post a Comment