Reputation: 157
I want to generate a JSON like this:
{ “index”:{} }
Here is the code I'm using:
JSONObject indexObject = new JSONObject( );
indexObject.put( "index", new JSONArray());
but it outputs this:
{"index":[]}
Upvotes: 2
Views: 6491
Reputation: 2571
That happens, because you are putting JSONArray()
there. Try putting JSONObject()
just like that:
indexObject.put( "index", new JSONObject());
Thanks, @bhusak.
Upvotes: 3