读取本地 json文件并转成 model

1,读取本地 json

  NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"home" ofType:@"json"];
             NSData *data=[NSData dataWithContentsOfFile:jsonPath];
             NSError *error;
             id jsonObject=[NSJSONSerialization JSONObjectWithData:data
                                                           options:NSJSONReadingAllowFragments
                                                             error:&error];

2,把 son 转成 model

//HomePageMainModel写的 model
   homePageMainModel = [[HomePageMainModel alloc] initWithDictionary:jsonObject error:nil];
             NSLog(@"%@",homePageMainModel);

你可能感兴趣的:(读取本地 json文件并转成 model)