JSON 数据的系统解析
来源:互联网 发布:电脑网络维修上门 编辑:程序博客网 时间:2024/04/30 02:10
- (IBAction)jsonSystemButtonDidClicked:(UIButton *)sender { self.JSONArray = [NSMutableArray array]; // 1、拿到 json 文件的路径 NSString *path = [[NSBundle mainBundle] pathForResource:@"student" ofType:@"json"]; // 2、根据路径获取文件内容为 NSData 对象 NSData *data = [NSData dataWithContentsOfFile:path]; // 3、解析开始 NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil]; 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); }}
@property (nonatomic, strong) NSMutableArray *JSONArray;
当模型中类型冲突时
@implementation StudentModal- (NSString *)description{ return [NSString stringWithFormat:@"%@, %@, %@, %ld, %@", self.name, self.sex,self.phoneNumber, self.number, self.hobby ];}- (void)setValue:(id)value forKey:(NSString *)key{ // super 必须写 [super setValue:value forKey:key]; if ([key isEqualToString:@"number"]) { self.number = [value integerValue]; }}
1 0
- JSON 数据的系统解析
- json 的数据解析
- JSON数据的解析
- JSon数据的解析
- JSON数据的解析
- JSon数据的解析
- json的数据解析
- Json数据的解析
- JSON数据的解析
- JSON数据的解析
- json数据的解析
- JSON数据的解析
- Json数据的解析
- Json数据的解析
- Json数据的解析
- JSON数据数据的解析
- 【数据解析】Android Json数据的解析
- 解析JSON数据的步骤
- OC类 之 NSString
- [基本实验] 探测Web目录结构和隐藏的敏感文件
- OC的字符串
- Objective-C的指令
- 数据库连接池------------0
- JSON 数据的系统解析
- 修改原生cell.imageView.image的大小
- Android Studio添加so库文件方法
- NSLineBreakByWordWrapping和NSLineBreakByCharWrapping的异常
- 在MVC的WebApi中默认是没有开启Session会话支持的。需要在Global中重写Init方法来指定会话需要支持的类型
- 编码心得
- 【Linux-shell】shell脚本基础语法练习
- Java关键字this、super使用总结
- js 动画1