2016-02-03 73 views
0

我在一個項目中使用AFNetworking的最新版本,該項目連接到返回文本響應和JSON響應的API,因此我使用AFCompoundResponseSerializer來處理這兩個響應。AFCompoundResponseSerializer JSON問題

請求返回一個JSON文件中給我的JSON響應,而不是被normaly與AFJsonResponseSerializer返回NSDictionnaryNSString,它看起來像AFCompoundResponseSerializer採取響應爲純文本,不會將其發送到在AFJsonResponseSerializer

我的代碼脫穎而出CompoundSerializer情況如下:

 sharedSessionManager = [[self alloc] initWithBaseURL:[NSURL URLWithString:baseURL]]; 
    sharedSessionManager.responseSerializer=[AFCompoundResponseSerializer compoundSerializerWithResponseSerializers:@[[AFJSONResponseSerializer serializer], [AFHTTPResponseSerializer serializer]]]; 

回答

0

我發現爲什麼會這樣:

服務器返回的JSON爲text/html,所以串行器直接發送給AFHTTPResponseSerializer,它返回一個字符串,而不是解析JSON。

爲了解決這個問題,只需添加text/html到JSON序列的acceptableContentTypes