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 }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。