1

I am parsing the json data in iphone sdk, but the problem is after i parsed it i am getting the data in sorted order based on the alphabetic. when i see the json structure in json online viwer i am getting the objects correctly something like Physician name: Designation: Adress: Fax:

but after i parsed the json data in iphone i am getting some thing like this

Adress: Designation: Fax: PhysicianName:

how to avoid the sorting while parsing the json in iphone.

Shiva Reddy
  • 456
  • 1
  • 7
  • 26

2 Answers2

3

Order in Json object is unspecified and is application dependent. If your values are ordered you have to put them in a list.

http://www.ietf.org/rfc/rfc4627.txt

The RFC only specify that key should be unique.

Your question is a duplicate from : JSON order mixed up

  • Why do you need to keep the order ?
  • Do you have any control of the data coming from the server ?
Community
  • 1
  • 1
VGE
  • 4,171
  • 18
  • 17
  • Thank you for your reply VGE. what i want is after i parsed the json i am getting the sorted objects based on alphabetic. i need as it is object structure. don't want sorted objects. for iphone i found some json library, when i parsed the data the output i am getting in sorted format. – Shiva Reddy May 10 '11 at 11:58
2

I guess you use a NSDictionary to parse the data into. And i guess NSDictionary sorts them based on keys. why do you want to worry about order if you are going to access it based on keys.

UPDATE

allValues

Returns a new array containing the dictionary’s values.

- (NSArray *)allValues

Return Value

A new array containing the dictionary’s values, or an empty array if the dictionary has no entries.

Discussion

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

It clearly states the order is not defined. So i guess its better to use the dictionary as such and use the keys to load your table

visakh7
  • 26,380
  • 8
  • 55
  • 69
  • Hi, Thank for quick response.i want the same order bcz i am getting the key and value pairs both from server, i don't know the order, so what ever order i am getting from the server i am retriving the info from dictionary after parsing as [dict allvalues] and [dict allkeys] and i am using this data to load it into table, in the table this order shouldn't be missed. – Shiva Reddy May 10 '11 at 12:02
  • It is better to get the dict as such and use the keys to fill your table. – visakh7 May 10 '11 at 12:05
  • Hi, I did the same took the allvalues from the dictionary and formed the order.thanks – Shiva Reddy May 10 '11 at 14:09