I have a JSON return being formatted and saved into a plist, it looks like the following:
alt text http://www.baublet.com/images/array3.png
I need it to have the following format:
alt text http://www.baublet.com/images/array4.png
I’m missing something in the saving of the array so I can add the “Rows” below the Root and “Item 0, etc” under the profile, any ideas?
Here is my code:
NSURL *url = [NSURL URLWithString:@"http://10.0.1.8/~imac/iphone/jsontest.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSLog(jsonreturn); // Look at the console and you can see what the results are
SBJSON *json = [[SBJSON alloc] init];
NSError *error = nil;
rowsArray= [json objectWithString:jsonreturn error:&error];
//ADDED from COMMENT AS TEST
test = [rowsArray valueForKey:@"member"];
//Saving
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *choiceR = [documentsDirectory stringByAppendingPathComponent:@"FollowingArray"];
NSMutableArray *array = [[NSMutableArray alloc] init];
NSLog(@"string: %@",choiceR);
[array addObject:rowsArray];
[array writeToFile:choiceR atomically:YES];
[array release];
[jsonreturn release];
[json release];
Here is the test plist from the test:
Create an NSDictionary with your
rowsArrayas the value for the key@"Rows". Then save that dictionary instead of the array.You’ll have to grab the
profiledictionary for each item and manually convert it to the desired format, then replace the dictionary with the resulting array. This is nothing that can be done in one or two lines but it shouldn’t be too difficult. Just grab the keys of the dictionary and for each of them, create a new dictionary with the desired key/value pair, then add all these dicts to an array.