Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c AFN不读取JSON数据_Objective C_Json_Afnetworking_Afnetworking 2 - Fatal编程技术网

Objective c AFN不读取JSON数据

Objective c AFN不读取JSON数据,objective-c,json,afnetworking,afnetworking-2,Objective C,Json,Afnetworking,Afnetworking 2,我正在使用AFNetworking从印度铁路公司的erail apiAPI获取数据。我使用此代码获取json数据 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; operation.responseSerializer = [AFJSONResponseSerializer serializer]; json数据如下所示: 以下setcomplet

我正在使用AFNetworking从印度铁路公司的erail apiAPI获取数据。我使用此代码获取json数据

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];
json数据如下所示: 以下setcompletionblock返回错误

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"YES!");
        returnedData = [[NSData alloc] initWithData:responseObject];
        done = YES;
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"NO!");
        done = YES;
    }];
错误是: po错误


它说内容是html/text,但我看到的是json。你知道如何纠正这个问题吗?

既然你无法控制服务器的头,你可以尝试这样做:你也可以联系服务器管理员来更改内容类型头:在这种情况下,它应该是application/json。我认为[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObjects:@text/html,nil]];在AFnetworking 2.0中不推荐使用,但这里还有其他类似的方法:例如使用管理器。。。。最坏情况下的解决方法是使用AFHTTPResponseSerializer并手动解析结果。它在文档中:谢谢!我已经改正了。
Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x100309bb0 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x100238920> { URL: http://api.erail.in/pnr?key=599c66c2-493d-47e6-abe9-af&pnr=673604 } { status code: 200, headers {
"Cache-Control" = private;
"Content-Encoding" = gzip;
"Content-Length" = 239;
"Content-Type" = "text/html; charset=utf-8";
Date = "Wed, 31 Dec 2014 19:32:26 GMT";
Expires = "Thu, 01 Jan 2015 19:32:26 GMT";
Server = "Microsoft-IIS/8.5";
"Set-Cookie" = "ASP.NET_SessionId=fokkb5afytprm3uw1puurljo; path=/; HttpOnly";
"X-AspNet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";
} }, NSErrorFailingURLKey=http://api.erail.in/pnr?key=599c66c2-493d-47e6-abe9-64ae81b&pnr=67360, com.alamofire.serialization.response.error.data=<7b227374 61747573 223a224f 4b222c22 72657375 6c74223a 7b22706e 72223a22 36373336 30343230 3637222c 22636c73 223a2253 4c222c22 65746963 6b657422 3a747275 652c226a 6f75726e 6579223a 2230342d 4a616e2d 32303135 222c2274 7261696e 6e6f223a 22313237 3237222c 226e616d 65223a22 474f4441 56415249 20455850 222c2266 726f6d22 3a224456 44222c22 746f223a 22534322 2c226272 6467223a 22445644 222c2270 61737365 6e676572 73223a5b 7b22626f 6f6b696e 67737461 74757322 3a22572f 4c202032 3332474e 574c222c 22637572 72656e74 73746174 7573223a 2243616e 2f4d6f64 222c2263 6f616368 223a2222 7d5d2c22 63686172 74223a22 43484152 54204e4f 54205052 45504152 4544222c 22657272 6f72223a 22227d7d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}