一、生成json文件
将json数据粘贴到这个网站https://www.bejson.com/ 格式化->保存到本地
二、在xcode里用下面代码生成plist文件
NSString *path = [[NSBundle mainBundle] pathForResource:@"cityjsonfile.json" ofType:nil];
NSArray *array = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableLeaves error:nil];
NSString *newPath = [NSString stringWithFormat:@"/Users/用户名/Desktop/cityFile.plist" ];
[array writeToFile:newPath atomically:NO];
三、根据plist文件生成模型数据
1、将文件添加大到需要的工程里
2、用NSDictionary
获取plist文件信息
[NSDictionary dictionaryWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"cityFile.plist" withExtension:nil]];
3、根据数据新建模型 并 通过 MJExtension 解析即可
网友评论