如果我的json响应是一个空对象,我想通过不创建OPLocationModel来处理这种情况 我的json响应如下" location":{} - >一个空的对象,
例如: location - 有一个id
NSDictionary *locationData = data[@"location"];
if(locationData){
OPLocationModel *locationModel = [OPLocationModel modelWithJSONData:locationData withContext:context];
model.location = locationModel;
}
else{
model.location = nil;
}
这是做到这一点的最佳方法还是有更好的建议?
解决了
NSDictionary *locationData = data[@"location"];
if([locationData objectForKey:@"id"] != nil){
OPLocationModel *locationModel = [OPLocationModel modelWithJSONData:locationData withContext:context];
model.location = locationModel;
}