http://api.yytianqi.com/citylist/id/1
结合省市区的json数据解析出来,取出所有城市,放入数组,将数组写入plist
"city_id": "CH010100",
"name": "北京",
"en": "Beijing"
如下:
NSString *file = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *filePath = [file stringByAppendingPathComponent:@"MyCity.plist"];
NSFileManager *manager = [NSFileManager defaultManager];
NSDictionary *chinaDic= [dic objectForKey:@"list"];//34个省份
NSMutableArray *newArr = [NSMutableArray array];
for (NSDictionary *shengDic in chinaDic) {
NSDictionary *sDic = [shengDic objectForKey:@"list"];//省份里的市
for (NSDictionary *shiDic in sDic) {
NSDictionary *cDic = [shiDic objectForKey:@"list"];
if (cDic == nil) {//直辖市只有一个市
[newArr addObject:shiDic];
} else {//省有多个市
for (NSDictionary *quDic in cDic) {
[newArr addObject:quDic];
}
}
}
}
if ([manager createFileAtPath:filePath contents:nil attributes:nil] == YES) {
[newArr writeToFile:filePath atomically:YES];
}
最终的plist中数据格式如下