I have a .net webservice which returns a Json data in this format:
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:dataPlist options:NSJSONReadingMutableContainers error:&errorJson];
[
{
"MEMBERID": "xxx",
"PREFIXINFORMAL": "Mr.",
"FIRSTNAME": "xxx",
"MIDDLENAME": "xxxx",
"LASTNAME": "xxxx",
"SUFFIX": xxxx
}
]
My code to save this NSDictionary to plist:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"boardMemberInfo.plist"];
NSDictionary *test = [NSDictionary dictionaryWithObject:@"test" forKey:@"test"];
for(NSDictionary *item in json) {
BOOL success = [item writeToFile:path atomically:YES];
if(success) {
NSLog(@"Success Saving New plist");
} else {
NSLog(@"Failure Saving New plist");
}
}
Neither [item writeToFile…] nor [json writeToFile…] works. However, simple [test writeToFile…] works. What am I missing?
Thanks,
Best thing you could do is to decompose your saving process and use NSError to understand what the problem is: