AFJSONRequestOperation失败,因为webservice返回内容类型为text/html的JSON

Sle*_*lee 3 objective-c ios afnetworking

我正在尝试更新我的应用程序以使用AFNetworking,但我需要使用的Web服务将JSON作为text/html返回,当我尝试使用AFJSONRequestOperation时它会破坏:

Expected content type {(
    "text/json",
    "application/json",
    "text/javascript"
)}, got text/html
Run Code Online (Sandbox Code Playgroud)

反正有没有在AFNetworking中覆盖它,所以我可以接受text/html?

Fel*_*lix 13

是的,AFNetworking支持添加可接受的内容类型.在AFHTTPClient子类的init方法中,执行以下操作:

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObjects:@"text/html", nil]];
Run Code Online (Sandbox Code Playgroud)

我的应用程序遇到了同样的问题,这使它成功了.