My code to create a new JSONObject and write to a file:
JSONObject obj = new JSONObject(); obj.put(\"name\", \"abcd\"); obj.put(\"age\", new Integer(100)); J
The JSONObject class doesn't have a toJSONString() method. Instead it overrides the toString() method to generate json.
toJSONString()
To get the json representation of the object, simply use obj.toString().
obj.toString()