私がフェッチする私の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 のバックグラウンドから来ています)。