toJSONString() is undefined for the type JSONObject

前端 未结 4 1557
情歌与酒
情歌与酒 2021-01-02 15:21

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         


        
4条回答
  •  温柔的废话
    2021-01-02 16:08

    The JSONObject class doesn't have a toJSONString() method. Instead it overrides the toString() method to generate json.

    To get the json representation of the object, simply use obj.toString().

提交回复
热议问题