0
我试图映射具有动态嵌套属性的API结果。结果(json)我是这样的:RestKit动态嵌套属性
{
"url": "https://api.github.com/gists/8901308",
"id": "8901308",
"html_url": "https://gist.github.com/8901308",
"files": {
"node-and-npm-in-30-seconds.sh": {
"filename": "node-and-npm-in-30-seconds.sh",
"type": "application/sh",
"language": "Shell",
"raw_url": "https://gist.github.com/braincrash/8901308/raw/bae861f7c4ab0c1ffd9962439e770b02f52c5dd7/node-and-npm-in-30-seconds.sh",
"size": 352
},
"only-git-all-the-way.sh": {
"filename": "only-git-all-the-way.sh",
"type": "application/sh",
"language": "Shell",
"raw_url": "https://gist.github.com/braincrash/8901308/raw/eba9667b37218ffb41892411c94abd051b0e269a/only-git-all-the-way.sh",
"size": 440
}
}
}
我可以得到所有的属性,但文件不起作用。这里是我的映射:
RKEntityMapping *fileMapping = [RKEntityMapping mappingForEntityForName:@"File" inManagedObjectStore:managedObjectStore];
fileMapping.forceCollectionMapping = YES;
[fileMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"filename"];
[fileMapping addAttributeMappingsFromDictionary:@{@"(filename).raw_url": @"rawURL",
@"(filename).size": @"size"}];
RKEntityMapping *gistMapping = [RKEntityMapping mappingForEntityForName:@"Gist" inManagedObjectStore:managedObjectStore];
[gistMapping addAttributeMappingsFromDictionary:@{
@"id": @"gistID",
@"url": @"jsonURL",
@"html_url": @"htmlURL"}];
gistMapping.identificationAttributes = @[ @"gistID" ];
[gistMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"files" toKeyPath:@"files" withMapping:fileMapping]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:gistMapping method:RKRequestMethodGET pathPattern:@"/gists/public" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
当我看着主旨物体内部的文件,我只得到文件名,而不是网址或大小:
filename = "radiation.js";
gist = "0xb9742f0 <x-coredata://D37E442D-45BA-4A0E-B7A5-A349F75FA362/Gist/p21>";
rawURL = nil;
size = 0;
感谢您的帮助!
可能是因为你的文件名包含点,所以他们会搞乱关键路径导航。打开跟踪日志记录来检查。你有选择更改JSON吗? – Wain
你是赖特。我发现一个没有点的钥匙,工作得很好。哟可以添加一个答案,我会标记它是正确的。你知道这个问题的解决方法吗?谢谢 – amcastror