Add JsonArray to JsonObject

前端 未结 5 1796
予麋鹿
予麋鹿 2020-11-27 20:52

I googled a lot today for this subject. But I can\'t find it, How can I add a JSONArray to a JSONObject?

Because everytime I do this I get this error: Stackoverflow<

5条回答
  •  無奈伤痛
    2020-11-27 21:10

    I think it is a problem(aka. bug) with the API you are using. JSONArray implements Collection (the json.org implementation from which this API is derived does not have JSONArray implement Collection). And JSONObject has an overloaded put() method which takes a Collection and wraps it in a JSONArray (thus causing the problem). I think you need to force the other JSONObject.put() method to be used:

        jsonObject.put("aoColumnDefs",(Object)arr);
    

    You should file a bug with the vendor, pretty sure their JSONObject.put(String,Collection) method is broken.

提交回复
热议问题