JSON 数据的 JSONKit 解析

@property (nonatomic, strong) NSMutableArray *JSONArray;

懒加载

– (NSMutableArray *)JSONArray{if (_JSONArray == nil) {self.JSONArray = [NSMutableArray array];}return _JSONArray;}- (IBAction)JSONKitButtonDidClicked:(UIButton *)sender {// 1、拿到 json 文件的路径NSString *path = [[NSBundle mainBundle] pathForResource:@”student” ofType:@”json”];// 2、根据路径获取文件内容为 NSData 对象NSData *data = [NSData dataWithContentsOfFile:path];// 3、解析为数组NSArray *array = [data objectFromJSONData];for (NSDictionary *dict in array) {StudentModal *modal = [StudentModal new];[modal setValuesForKeysWithDictionary:dict];[self.JSONArray addObject:modal];}for (StudentModal *modal in self.JSONArray) {NSLog(@”JSONArray = %@, %ld, %@”, modal.name, modal.number, modal.hobby);}[self.JSONArray removeAllObjects];// 把OC里面的数据类型转化成 json 串NSString *yadong;[yadong JSONString];NSArray *testArray = @[@”wewe”, @”www”, @”qq”];NSString *result = [testArray JSONString];NSLog(@”result = %@”, result);}

,如果有可能,我带你去远行。躺在德德玛的草原,

JSON 数据的 JSONKit 解析

相关文章:

你感兴趣的文章:

标签云: