How can i sort my JSON object based on Key?

后端 未结 3 1413
南旧
南旧 2021-01-13 18:55

I am creating a JSON object in which i am adding a key and a value which is an array. The value for both key and value comes from a TreeSet which has data in sorted form. Ho

3条回答
  •  爱一瞬间的悲伤
    2021-01-13 19:45

    Below are what the doc says from http://www.json.org/java/index.html.

    "A JSONObject is an unordered collection of name/value pairs."

    "A JSONArray is an ordered sequence of values. "

    In order to get an sorted Json Object, you can use Gson which is already provided a good answer by @user748316.

提交回复
热议问题