I am adding key value strings to an NSArray, but they are added in the wrong order, which leads me to believe that this is the wrong way to do things-
my json takes the following format:
[{
"story1":
{data in here}
"story2":
{data in here}....
and in my code I am wishing to get the string values of story1 and story2 (and more) in an NSArray, which I achieve but they are in the opposite order - story2, story1:
NSArray *jsonArr = [NSJSONSerialization JSONObjectWithData:theData options:kNilOptions error:&error];
for (NSString *pItem in [jsonArr objectAtIndex:0]) {
NSLog(@"Product: %@", pItem);
}
is there a better way to do this, and if not, how can i reverse the array?
[..]is a JSON array.{..}is a JSON "object", which is essentially the same as a Objective-C NSDictionary. By definition (the JSON spec), elements of an "object" are unordered.){}. The dictionary is in an array, but it's kind of a degenerate case of an array with only one element. (Study the JSON spec to understand this.)