我在通过JSONModel库https://github.com/icanzilb/JSONModel读取JSON时遇到问题
并在JSonModel应用程序json中使用KivaDemo:
"loans": [
{
"id": 547665,
"name": "Veronica",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
我想得到“ en”,
@interface KivaFeed : JSONModel
@property (strong, nonatomic) NSArray<LoanModel, ConvertOnDemand>* loans;
@property (strong, nonatomic) Paging *paging;
@end
@protocol LoanModel @end
@interface LoanModel : JSONModel
@property (strong, nonatomic) NSString* name;
@property (strong, nonatomic) NSString* status;
@property (strong, nonatomic) NSString* use;
@property (strong, nonatomic) NSString* id;
@property (strong, nonatomic) NSString* funded_amount;
@property (strong, nonatomic) LocationModel* location;
@property (strong, nonatomic) Image* image;
@property (strong, nonatomic) Description* description;
@end
@interface说明:JSONModel
@property (strong, nonatomic) NSArray<Languages, ConvertOnDemand>* languages;
@end
@protocol Languages @end
@interface Languages : JSONModel
@end
kiva = [[KivaFeed alloc] initFromURLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"
completion:^(JSONModel *model, JSONModelError *e) {
[table reloadData];
NSLog(@"kiva.paging.page:%@",kiva.paging.page);
if (e) {
[[NSAlert alertWithError:e] beginSheetModalForWindow:self.view.window modalDelegate:nil didEndSelector:nil contextInfo:nil];
}
[self setLoaderVisible:NO];
}];
LoanModel* loan = kiva.loans[row];
NSString* message = [NSString stringWithFormat:@"%@ from %@(%@) needs a loan %@",
loan.name, loan.location.country, loan.location.countryCode, loan.use
];
NSLog(@"loan:%@",loan.id);
NSLog(@"loan:%@",loan.funded_amount);
NSLog(@"loan.image.id:%@",loan.image.id);
NSLog(@"loan.description.languages:%@",loan.description.languages[0]);
最后它给了我2013-04-15 13:16:09.163 JSONModelDemo_OSX [2308:303] loan.description.languages:(null)。如何获取en,我的代码有什么错误?
最佳答案
修改为:
@interface Description : JSONModel
@property (strong, nonatomic) NSArray* languages;
@end
一切都很好