【发布时间】:2015-07-27 09:06:14
【问题描述】:
我有一个包含 json 文件的链接。我的意思是,如果我在 chrome 中启动该链接,则会在我的计算机上下载一个扩展名为 .json 的文件。
说链接是www.foffa.com/sampleList.json
我是 AFNetworking 的新手,不确定如何解析这个 json,无论是否必须将此文件写入磁盘。
我的代码如下所示,我很确定我必须使用流和所有这些,但我不确定如何。截至目前我收到一个错误"Request failed: unacceptable content-type: text/plain"
我猜它期望内容类型为"Content-Type" = "application/octet-stream";
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFHTTPResponseSerializer serializer];
operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/octet-stream"];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Data retrived");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];
【问题讨论】:
-
您回复的内容类型似乎设置为
text/plain。您需要将其从服务器端更改为您接受的服务器端,或者您需要添加text/plain作为可接受的内容类型。
标签: ios iphone afnetworking-2