JSON->NSData
1 - (IBAction)touchWriteButton:(id)sender { 2 NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; 3 [dictionary setValue:@"Anthony" forKey:@"First Name"]; 4 [dictionary setValue:@"Robbins" forKey:@"Last Name"]; 5 [dictionary setValue:[NSNumber numberWithUnsignedInteger:51] forKey:@"Age"]; 6 NSArray *arrayOfAnthonysChildren = [[NSArray alloc] initWithObjects:@"Anthony's Son 1", @"Anthony's Daughter 1", @"Anthony's Son 2", @"Anthony's Son 3", @"Anthony's Daughter 2", nil]; 7 [dictionary setValue:arrayOfAnthonysChildren forKey:@"children"]; 8 NSError *error = nil; 9 NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:&error]; 10 if (error) { 11 NSLog(@"dic->%@",error); 12 } 13 [dictionary release]; 14 BOOL succeed = [jsonData writeToFile:JSON_PATH atomically:YES]; 15 if (succeed) { 16 NSLog(@"Save succeed"); 17 }else { 18 NSLog(@"Save fail"); 19 } 20 }