所以我最近想從使用NSUrlConnection更改爲AFNetworking。使用AFNetworking時,我可以用兩種方法接收JSON數據,但有些奇怪的事情發生了。使用AFNetworking抓取問題JSON
這是怎麼看起來像NSURLConnection的
,這是它的樣子與AFNetworking
我也不知道這是什麼(結構__lidb_autoregen_nspair)是,我不知道這是否是阻止我顯示數據的東西
這是從AFNetworking的代碼,我使用示例代碼從射線
-(void) fetchData{
// 1
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// 2
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// 3
jsonDict = (NSMutableDictionary *)responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// 4
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];
// 5
[operation start];
}
--------------------------- -------------------------------------------------- ------------編輯
-(NSMutableDictionary *) getAllGames{
[self fetchData];
DataParser *dataParserObjec = [[DataParser alloc] init];
return [dataParserObjec sendBackAllGames:jsonDict];
}
'acceptableContentTypes'不應該是'application/json'? – Larme 2014-12-02 10:26:05
嗯,這可能是問題。當我沒有那行代碼sayin文本/ HTML我遇到了錯誤塊。我猜我的服務器沒有發送JSON然後對嗎? 但它爲什麼與NSURLConnection一起使用? @Larme – 2014-12-02 10:28:50
所以這裏唯一的解決方法是讓服務器發送回json @rob – 2014-12-02 11:36:40