Hi All,

I am trying to write a dynamic JSON formatter based on my business logic. I am trying something like this:


Code:

JSONArray testArray= new JSONArray();
JSONObject obj1 = new JSONObject();
obj1.put("TestKey","Test Value");
testArray.add(obj1);

This works perfectly with the JSONObject showing up in the JSONArray.

However, when I try an anonymous class or simultanous JSONObject.put() inside JSONArray. The size of the array is updated but not the ENTRY i.e. I cant see any Key Value pair updated inside the array.

Code:

JSONArray testArray= new JSONArray();
JSONObject obj1 = new JSONObject();
testArray.add(obj1.put("TestKey","TestValue"));
[OR]

testArray.add(new JSONObject().put("TestKey","TestValue"));


Thank you all in advance.

Harsh