1

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 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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.
Means I have to get the result in Array?
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.
by using an nsarray it gives the same unordered result.What should I do now?
You have to fix it mainly where the JSON is generated in the first place, i.e. probably on the server side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.