只是試圖在這裏適應iphone應用程序的restkit,並且我擊中了牆。我試圖從嵌套的JSON文件中獲取數據。嵌套的JSON與iPhone上的restkit iphone
[
{"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"];
那麼人類和數字類如下
#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保持爲空而名稱和id變量填充正常。 有關於此的任何想法? 我試圖在git上的例子,但沒有得到它的工作,所以任何幫助將不勝感激。 感謝 摹
沒有它仍然無法正常工作。實際上,數字課程甚至從未被調用過。我嘗試了目錄示例,並使用它的類而不是我的類,並以與示例中相同的方式調用它們,但仍然沒有喜樂。它仍然只加載非數組數據。 – glogic 2011-06-02 10:25:57