JSONkit sorting issues

前端 未结 2 1331
名媛妹妹
名媛妹妹 2021-01-26 10:06

I am using a REST based web service to get data. No matter what the structure of the JSON document, the NSDictionary gets populated the same way. I want the sorting preserved as

相关标签:
2条回答
  • 2021-01-26 10:37

    You shouldn't be using JSON dictionary to store things whose order matters. As http://json.org/ says

    An object is an unordered set of name/value pairs.

    0 讨论(0)
  • 2021-01-26 10:48

    The entries in an NSDictionary have no inherent order; they are unsorted by definition. The same is true for the array returned by allValues, as the documentation clearly says:

    The order of the values in the array isn’t defined.

    You will need to sort the array afterwards. If you want to keep the same sort order that is in the JSON source, you would have to parse the JSON data manually and retrieve the values from the dictionary one after another. Or, if you know how the JSON data is sorted, just apply the same sorting algorithm to the array returned by allValues.

    0 讨论(0)
提交回复
热议问题