Hi I am using a php api in my ios app and I want the result in an Specific order . It gives the correct order if i parse it in browser by online tools.But as I am using NsJsonSerialisation to Parse it into any of foundation object I am getting reordered list of data.The Order is not Alphabetic,So I am unable to make it at my end.
1 Answer
If you want a specific order, you need to use a JSON array:
[
"one",
"two",
"three"
]
instead of a JSON object.
The elements in a JSON object have not fixed order. And a JSON object becomes a NSDictionary instance in Objective-C, whose elements have no order either.
5 Comments
Ruchira Randana
Yes, I think @Codo has given the answer. You must be using a Dictionary. You should use an Array instead. Please show us your JSON for further proof.
Anuj Garg
Means I have to get the result in Array?
Codo
Yes, it must be produced with an array instead of an object in the first place. And then you have to use a NSArray instead of an NSDictionary instance in Objective-C.
Anuj Garg
by using an nsarray it gives the same unordered result.What should I do now?
Codo
You have to fix it mainly where the JSON is generated in the first place, i.e. probably on the server side.