To pass data to my webservice, I create an NSDictionary with the objects and keys I need, and use JSONRepresentation to format it nicely so I can post it to my service.
It all worked fine with the previous version where only 2 parameters were required. An array with listitems, and a UDID.
No I also need to pass a version number because we need to provide more data for people with the application at this new version.
Only problem is when I create my JSONRepresentation now, the order of things are all messed up.
NSMutableDictionary开发者_开发技巧 *rowDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:arrayDict,@"basketListV2",sharedData.udid,@"UDID",@"1.4",@"version",nil];
It prints out version first, then UDID and then basketListV2.
Anyone know what I can do to maintain the order of my NSDict? I tried both NSDictionary and NSMutableDictionary (Probably doesn't have to do anything with it but for testing purposes I had to try it.)
Thanks in advance.
Lewion
The order of a NSDictionary is undefined unless the keys are strings (see http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html)
Anyway, ordering does not make a lot of sens for a dictionary. So you should not be preoccupied by it even at the JSON representation level.
If you really need to get these things ordered (and make sure it will stay ordered across version change), use NSArrays which are by interface ordered collections of objects. (see http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html)
Cheers,
-stan
精彩评论