gpt4 book ai didi

ios - Rails 3.2.8 + RestKit - 没有 KVC 的映射

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:59 25 4
gpt4 key购买 nike

所以我尝试使用 RestKit 从我的 Rails 应用程序中获取 JSON 格式的信息

我的代码是这样的:

应用委托(delegate)

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

//Initialise RestKit
NSURL *URL = [NSURL URLWithString:@"https://myapp.dev"];
AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:URL];

//Enable Activity Indicator Spinner
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;


[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];

RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];


RKObjectMapping *eventMapping = [RKObjectMapping mappingForClass:[Info class]];

[infoMapping addAttributeMappingsFromDictionary:@{
@"sample":@"sample",
@"sample_1":@"sample_1"
}];

RKResponseDescriptor *infoDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:infoMapping
pathPattern:@"/info"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[objectManager addResponseDescriptor:infoDescriptor];
}

查看文件

- (void)loadInfo
{

RKObjectManager *objectManager = [RKObjectManager sharedManager];

[objectManager getObjectsAtPath:@"/info"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

NSArray *info = [mappingResult array];

NSLog(@"Loaded info: %@", info);


_info = info;


} failure:^(RKObjectRequestOperation *operation, NSError *error) {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error getting into"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);

}];
}

问题是。在日志输出中,RestKit 告诉我它成功映射了所有内容。但是当我尝试使用登录 View 文件的方法和使用 po 的调试器查看对象时,我得到以下信息

374 Finished performing object mapping. Results: {
"<null>" = "<Info: 0xa291b30>";
}

我无法查看对象和断点,它显示为:

Object exists but cannot view it

我已经为此苦苦挣扎了几天,我不确定还能尝试什么。任何帮助将不胜感激

最佳答案

我遇到了类似的问题。我不太清楚为什么,但是当我执行以下操作时它修复了它。

- (void)loadInfo
{

RKObjectManager *objectManager = [RKObjectManager sharedManager];

[objectManager getObjectsAtPath:@"/info"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

NSArray *info = [mappingResult array];
NSLog(@"Loaded info: %@", info);
_info = info;


} failure:^(RKObjectRequestOperation *operation, NSError *error) {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error getting into"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);

}];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

//Initialise RestKit
NSURL *URL = [NSURL URLWithString:@"https://myapp.dev"];
AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:URL];

//Enable Activity Indicator Spinner
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;


[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];

RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];


RKObjectMapping *eventMapping = [RKObjectMapping mappingForClass:[Info class]];

[infoMapping addAttributeMappingsFromDictionary:@{
@"sample":@"sample",
@"sample_1":@"sample_1"
}];

RKResponseDescriptor *infoDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:infoMapping
pathPattern:@"/info/:id"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[objectManager addResponseDescriptor:infoDescriptor];
}

关于ios - Rails 3.2.8 + RestKit - 没有 KVC 的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14087760/

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