gpt4 book ai didi

ios - 如何使用 JSONModel 获取 NSArray 对象

转载 作者:行者123 更新时间:2023-11-29 03:59:54 25 4
gpt4 key购买 nike

我在通过 JSONModel 库读取 JSON 时遇到问题 https://github.com/icanzilb/JSONModel

并在 JsonModel 应用程序中使用 KivaDemo,json :

"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

一切都好

关于ios - 如何使用 JSONModel 获取 NSArray 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16008105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com