I need to generate the JSON string in following format:
[{"param1":"value1","param2":"value2"},{"param1":"value3","param2":"value4"}]
I tried to store data in following way:
JSONArray jsonArray = JSONArray();
HashMap<String, String> hmap = new HashMap<String, String>();
hmap.put("param1", "value1");
hmap.put("param2", "value2");
jsonArray.add(hmap);
hmap = new HashMap<String, String>();
hmap.put("param1", "value3");
hmap.put("param2", "value4");
jsonArray.add(hmap);
System.out.print(jsonArray.toString());
But it generated the json string in following format:
["{param1:value1,param2:value2}", "{param1:value3,param2:value4}"]
What changes are need to get the string in required format?