// 獲取文件路徑 (1)
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"HomeData.json"];
//加載JSON文件(2)
NSString *dataStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//將文件內(nèi)容轉(zhuǎn)成數(shù)據(jù)(3)
NSData *jaonData = [dataStr dataUsingEncoding:NSUTF8StringEncoding];
//將數(shù)據(jù)轉(zhuǎn)成數(shù)組(4)
NSDictionary *dataDic = [NSJSONSerialization JSONObjectWithData:jaonData options:NSJSONReadingMutableContainers error:nil];
self.homeModel = [HomeMainModel yy_modelWithDictionary:dataDic];
問題:在(2)中况芒,獲取到dataStr為空绝骚。原因?yàn)樵?code>Copy Bundle Resources 中沒有添加這個文件粪牲,導(dǎo)致path找不到腺阳。