我相信我正在跳过一个重要的步骤或者说我的财产是错误的.在我的应用程序中,在使用登录信息创建POST对象后,我无法使用映射对象中的此信息(这意味着我得到空值).我假设在创建post请求和响应请求之后,我应该能够使用我的NSObjectClass中保存的值.
我的问题
在发布请求映射后如何保存值?如果有人可以提供一个如何使用response.body值的示例,那将非常有用.谢谢.
我的课程
#import <Foundation/Foundation.h>
@interface AccountsClass : NSObject
@property (nonatomic, strong) NSString *DeviceType;
@property (nonatomic,strong) NSString *HardwareId;
@property (nonatomic,strong) NSString *NickName;
@property (nonatomic,strong) NSNumber *HelpCreditsBalance;
@property (nonatomic,assign) BOOL GotRatingCreditBonus;
@property (nonatomic,strong) NSNumber *AccountId;
@end
Run Code Online (Sandbox Code Playgroud)
这是我用于POST请求的方法
-(void)loadPostRequest
{
_StoreIdentifierForVendor = [[[UIDevice currentDevice]identifierForVendor]UUIDString];
_StoreTheModel = [UIDevice currentDevice].model;
_nickname = usernameTextField.text;
AccountsClass *AccountInfo = [[AccountsClass alloc] init];
AccountInfo.NickName = _nickname;
AccountInfo.HardwareId =_StoreIdentifierForVendor;
AccountInfo.DeviceType =_StoreTheModel;
AccountInfo.AccountId =nil;
AccountInfo.GotRatingCreditBonus = FALSE;
AccountInfo.HelpCreditsBalance = nil;
//this is where the POST request begins
RKObjectMapping *responseMapping …Run Code Online (Sandbox Code Playgroud) 您好我使用restkit从api映射数据有问题.我有以下数据.我非常感谢任何可以指出我的错误的人.
{"GameId":1,"Items":
[{"Id":1,"PicUrl":"someurlhere","Answers":
["Paris","New York","San Francisco","Rome"],"CorrectAnswer":"San Francisco","Categories"}]}
Run Code Online (Sandbox Code Playgroud)
这就是我计划在客户端存储数据的方式:
#import <Foundation/Foundation.h>
GameObjects.h
@interface GameObjects : NSObject
@property(nonatomic, strong)NSNumber *GameId;
@property(nonatomic,strong)NSMutableArray *Items;
@property(nonatomic,strong)NSNumber *IId;
@property(nonatomic,strong)NSURL *PicUrl;
@property(nonatomic,strong)NSMutableArray *Answers;
@property(nonatomic,strong)NSString *CorrectAnswer;
@property(nonatomic,strong)NSString *CategoryName;
@end
GameObjects.m
#import "GameObjects.h"
@implementation GameObjects
@synthesize GameId;
@synthesize Items;
@synthesize Answers;
@synthesize IId;
@synthesize CategoryName;
@synthesize CorrectAnswer;
@synthesize PicUrl;
- (id)init
{
self = [super init];
if (self) {
Items = [[NSMutableArray alloc]initWithObjects:PicUrl,Answers,CorrectAnswer,CategoryName, nil];
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
这就是我如何进行映射:
-(void)viewDidLoad
{
//restkit
RKObjectMapping *GameMapping = [RKObjectMapping mappingForClass:[GameObjects class]]; …Run Code Online (Sandbox Code Playgroud)