我从本地组文件夹解析JSON文件它工作正常,但我使用资源组文件夹它不解析JSON文件,下面是我的代码,
我使用loacl组的路径是
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"nbg_ov_t_l_2_2" ofType:@"json"];
而不是我用于resoure文件夹的这一行,这里10Template是我的资源文件夹(蓝色文件夹)
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"nbg_ov_t_l_2_2" ofType:@"json" inDirectory:@"10Template"];//From resourse folder..
NSString *myJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
NSError *error12 = nil;
NSDictionary *jsonDataArray = [NSJSONSerialization JSONObjectWithData:[myJSON dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error12];
NSArray *jsonIdList=jsonDataArray[@"images"];
for(NSDictionary *tempIdList in jsonIdList)
{
NSString *orientation1;
orientation1=tempIdList[@"orientation"];
NSLog(@"orientation %@",orientation1);
}
这是我的JSON文件
{
"background_image":false,
"template_orientation":"landscape",
"background_colour":{
"red":202,
"green":150,
"blue":100,
"alpha":50
},
"images":[
{
"background_status":false,
"tilt_angle":0,
"orientation":"portrait",
"overlay":false,
"rect":
{
"x":0,
"y":0,
"width":100,
"height":100
}
},
{
"background_status":false,
"tilt_angle":25,
"orientation":"landscape",
"overlay":true,
"rect":
{
"x":25,
"y":60,
"width":30,
"height":50
}
}
]
}
我还有另一个疑问,如何从本地获取一些json文件(即我有10个json文件意味着我只想获得三个,我只解析那三个)以及如何解析它。 帮助我...