When i create a json object and add it to json array, it puts extra backslashes :/
1) Creating JSONObject
JSONObject jo = new JSONObject();
jo.put("JobName", "Test - Job Name");
jo.put("JobStatus", "Current");
jo.put("OrganID", "123");
jo.put("Date_Entered", getDate());
Result:
{"OrganID":"123","JobName":"Test - Job Name","Date_Entered":"13-Apr-2015","JobStatus":"Current"}
2) Adding JSONObject to JSONArray
JSONArray ja = new JSONArray();
ja.put(jo);
Result (It also puts extra double quotes " before and after JSONObject):
["{\"OrganID\":\"123\",\"JobName\":\"Test - Job Name\",\"Date_Entered\":\"13-Apr-2015\",\"JobStatus\":\"Current\"}"]
3) Adding JSONArray to JSONObject
JSONObject finalJson = new JSONObject();
finalJson.put("PostCompJob", ja.toString());
Result:
{"PostCompJob":"[\"{\\\"OrganID\\\":\\\"123\\\",\\\"JobName\\\":\\\"Test - Job Name\\\",\\\"Date_Entered\\\":\\\"13-Apr-2015\\\",\\\"JobStatus\\\":\\\"Current\\\"}\"]"}
I dont know why is this happening, can anyone please help me out?