首页 > 代码库 > ios网络请求3840错误的问题

ios网络请求3840错误的问题

ios网络请求3840错误的问题

by 伍雪颖

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unterminated string around character 11080.) UserInfo=0x171065d00 {NSDebugDescription=Unterminated string around character 11080.}

因为是用代理异步获取数据,数据是一段一段的,json格式不对,用NSMutableData合起来解析.

解决方法:
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
   
NSHTTPURLResponse*res = (NSHTTPURLResponse*)response;
    stateCode = [resstatusCode];
}

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data 4{
    [
self.dataJsonappendData:data];
   
NSError* error;
   
NSDictionary*jsonObject=[NSJSONSerialization
                             
JSONObjectWithData:self.dataJson
                             
options:NSJSONReadingMutableLeaves
                             
error:&error];
   
if (!error) {
       
self.responseBlock(stateCode,jsonObject);
    }
}

ios网络请求3840错误的问题