我用它工作了两天...我想获取远程 xml,然后将其解析/映射到核心数据。我已经阅读了一堆教程,所以此时我可以连接本地服务器(yyuupii!),获取 xml,但我在映射时遇到了问题。我明白了
-[RKObjectLoader canParseMIMEType:] 找不到 MIME 类型“application/xml”的解析器
-[RKObjectLoader isResponseMappable] 遇到意外响应,状态码:200(MIME 类型:application/xml -> URL:http:///list.xml -- http:/// -- http:/// -- http: ///) 2012-10-24 14:13:12.201 Sierpien[4650:907] Error Domain=org.restkit.RestKit.ErrorDomain Code=4 "操作无法完成。(org.restkit.RestKit.ErrorDomain错误 4.)"
你能给我一些建议吗,我将不胜感激。
我的 XML
<packs>
<pack>
<cover>cover.png</cover>
<info>Jakis.adres.pl</info>
<link>Opis</link>
<name>wrzesień</name>
<price>5.00</price>
</pack>
<pack>
<cover>cover2.png</cover>
<info>Jakis1.adres.pl</info>
<link>Opis31</link>
<name>wrzesień12</name>
<price>15.00</price>
</pack>
</packs>
我的实体
@interface Pack : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * link;
@property (nonatomic, retain) NSString * price;
@property (nonatomic, retain) NSString * info;
@property (nonatomic, retain) NSString * cover;
@end
我的实现
- (id)initClient
{
self = [super init];
if (self) {
RKObjectManager *client = [RKObjectManager objectManagerWithBaseURL:[RKURL URLWithString:@"http://10.1.1.5:8888/"]];
NSLog(@"I am your RKObjectManager singleton : %@", [RKObjectManager sharedManager]);
client.serializationMIMEType = RKMIMETypeXML;
RKObjectMapping* listMapping = [RKObjectMapping mappingForClass:[Pack class]];
[listMapping mapKeyPath:@"cover" toAttribute:@"cover"];
[listMapping mapKeyPath:@"name" toAttribute:@"name"];
[listMapping mapKeyPath:@"info" toAttribute:@"info"];
[listMapping mapKeyPath:@"link" toAttribute:@"link"];
[listMapping mapKeyPath:@"price" toAttribute:@"price"];
[[RKObjectManager sharedManager].mappingProvider setMapping:listMapping forKeyPath:@"packs.pack"];
}
return self;
}
- (void)loadPacks {
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/list.xml" delegate:self];
}