// //1、json转换成对象 // NSString * path = [[NSBundle mainBundle] pathForResource:@"test.json" ofType:nil]; // NSData * data = [NSData dataWithContentsOfFile:path]; // NSDictionary * dic = [ NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; // NSArray * array = dic[@"class1"]; // // for (NSDictionary * dic in array) // { // // //2.对象转成data // NSData * data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil]; // NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; // NSLog(@"%@", str); // // }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/3395.html