When JsonObject's keys are iterated they aren't in the same order as in the response from the server

前端 未结 3 605
滥情空心
滥情空心 2020-12-03 04:56

I have a very large response from server of JSON string. I converted it to JSON object and then get the keys and iterate it.

The problem is that when I iterate it is

3条回答
  •  囚心锁ツ
    2020-12-03 05:46

    The order of the keys of a JSON object is not supposed to be meaningful. If you want a specific order, you should use an array, not an object.

    Your Java code sorts the keys alphabetically. There is no way to get the initial ordering of the keys in the object.

    Reference 1:

    The order of the keys is undefined

    Reference 2:

    An object is an unordered set of name/value pairs

提交回复
热议问题