How can I get the output in the same order as I insert it into the arrays?
[NSDictionary dictionaryWithObjectsAndKeys: //I want it to be:
@"<xx3-xxxx>",@"from", //1st
@"<xxx-xxx>",@"to", //2nd
@"<Bla bla bla>",@"message", //3rd
@"<2000>",@"posixtime", nil]; //4th
Решение
The key/value pairs in an NSDictionary have no order. You may add them in that order but no order information is maintained inside the dictionary. So, when you create the JSON it comes out in an arbitrary order.
If you need the content in a certain order then you should either not use a dictionary or you should stream the items into the JSON in the order that you want (for example, with SBJson4StreamWriter).