现在只是想习惯这里的 iphone 应用程序的 restkit,我碰壁了。我试图从嵌套的 json 文件中获取数据。
[
{"person": {
"name": "joe",
"id": "1234",
"numbers":
[
{"value": "555-12125"},
{"value": "222-12125"}
]
}
}]
我像这样设置了rkobjectmanager
RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"http://localhost:3000"];
[manager loadObjectsAtResourcePath:@"/J.json?user_id=36995582&planner=insta-grammar" objectClass:[Person class] delegate:self] ;
[manager registerClass:[Person class] forElementNamed:@"person"];
[manager registerClass:[Numbers class] forElementNamed:@"numbers"];
那么person类和numbers类如下
#import "Person.h"
@implementation Person
@synthesize _name,_id,_number;
+ (NSDictionary*)elementToPropertyMappings {
return [NSDictionary dictionaryWithKeysAndObjects:
@"name",@"name",
@"id",@"id",nil];
}
+ (NSDictionary*)elementToRelationshipMappings {
return [NSDictionary dictionaryWithKeysAndObjects:
@"numbers", @"numbers",
nil];
}
@end
#import "Numbers.h"
@implementation Numbers
@synthesize _number;
+ (NSDictionary*)elementToPropertyMappings {
return [NSDictionary dictionaryWithKeysAndObjects:
@"value",@"value",nil];
}
+ (NSString*)primaryKeyProperty {
return @"value";
}
+ (NSDictionary*)relationshipToPrimaryKeyPropertyMappings {
return [NSDictionary dictionaryWithObject:@"value" forKey:@"value"];
}
@end
但是每次在调用 didloadobjects 函数后 _number 仍然为空,而 name 和 id 变量填充得很好。对此有什么想法吗?我在 git 上尝试了该示例,但无法使其正常工作,因此将不胜感激。谢谢克