我获取的 JSON:
{"username":"example","confirmed_rewards":"5","round_estimate":"0.73605946","total_hashrate":"0","payout_history":"10","round_shares":"85",
"workers":{
"worker.1":{"alive":"0","hashrate":"0"},
"worker.2":{"alive":"0","hashrate":"0"}
}
}
我的模型:
#import "JSONModel.h"
@protocol LKCoinFCPoolModel @end
@interface LKCoinFCPoolModel : JSONModel
@property (strong, nonatomic) NSString* username;
@property (strong, nonatomic) NSString* confirmed_rewards;
@property (strong, nonatomic) NSString* round_estimate;
@property (strong, nonatomic) NSString* total_hashrate;
@property (strong, nonatomic) NSString* payout_history;
@property (strong, nonatomic) NSString* round_shares;
@property (strong, nonatomic) NSString<Optional> * ErrorCode;
@end
我创建了以下函数,该函数用于获取 JSON 结构并将其分配给模型。
-(void)viewDidAppear:(BOOL)animated
{
//show loader view
[HUD showUIBlockingIndicatorWithText:@"Fetching JSON"];
//fetch the feed
LKCoinFCPoolModel* test;
test = [[LKCoinFCPoolModel alloc] initFromURLWithString:@"http://example.com/ap/key"
completion:^(LKCoinFCPoolModel *model, JSONModelError *err) {
//hide the loader view
[HUD hideUIBlockingIndicator];
//json fetched
NSLog(@"user: %@", test.username);
}];}
我遇到的问题是打印而不是user: example
打印user: (null)
.
我不确定我做错了什么,这是我尝试用 xcode 编写的第一个应用程序(我来自 Python/Java 背景)。