0
得到一个NSArray的对象,我有一个问题,在阅读JSON通过JSONModel库https://github.com/icanzilb/JSONModel如何使用JSONModel
,并使用KivaDemo在JSonModel应用程序,该JSON:
我想要得到的“恩”,
@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,我的代码有什么错误?
做其他的 “'NSLog'” 线条为你工作? –
是的,其他是正确的。 – pengwang