我刚开始使用restkit for ios.我有一个非常简单的json响应
{"result":[{"userid":"5964","name":"你的名字"}}}
这是一个有效的json(针对jsonlint测试)
但是,当我尝试将它与RKClient一起使用时,它不会将其视为json.这是我的代码
-(void) request:(RKRequest *)request didLoadResponse:(RKResponse *)response{
if([request isGET]){
if([response isJSON]){
NSLog(@"JSON Response from Server %@", [response bodyAsString] );
}else{
NSLog(@"Non JSON Response from Server %@", [response bodyAsString] );
}
}
}
Run Code Online (Sandbox Code Playgroud)
它总是记录"非JSON Reponse ...."但json完全有效.当我使用RKObjectMapping时会发生同样的事情; 错误将是"无法找到MIME类型text/xml的解析器.
任何帮助都非常感谢.
谢谢
如果由于任何原因您无法更改服务器标头并将Mime类型返回到xml或json,您仍然可以添加mime类型'text/html'的映射以作为json处理.
只需添加:
[[RKParserRegistry sharedRegistry] setParserClass:[RKJSONParserJSONKit class] forMIMEType:@"text/html"];
Run Code Online (Sandbox Code Playgroud)
并且不要忘记添加相关的头文件:
#import <RestKit/RKJSONParserJSONKit.h>
Run Code Online (Sandbox Code Playgroud)
适合我.
看看https://github.com/RestKit/RestKit/wiki/Using-a-Custom-MIME-Type
| 归档时间: |
|
| 查看次数: |
1529 次 |
| 最近记录: |