您好,登錄后才能下訂單哦!
概要:
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn't be completed. (Cocoa error 3840.)" (Unescaped control character around character 1419.) UserInfo=0x1563cdd0 {NSDebugDescription=Unescaped control character around character 1419.}
之前解析json的時候都是標準格式,json數據當中沒有 \n \r \t 等制表符。
今天在解析的時候發現json解析時好時壞,用在線json解析也米有問題。找了半天終于發現是制表符在作怪,由于標準的json解析是不允許有這幾個制表符的。所以在收到保溫的時候我們需要把這幾個制表符給過濾掉。
NSString * responseString = [request responseString]; responseString = [responseString stringByReplacingOccurrencesOfString:@"\r\n" withString:@""]; responseString = [responseString stringByReplacingOccurrencesOfString:@"\n" withString:@""]; responseString = [responseString stringByReplacingOccurrencesOfString:@"\t" withString:@""]; NSLog(@"responseString = %@",responseString); SBJsonParser *parser = [[[SBJsonParser alloc]init] autorelease]; id returnObject = [parser objectWithString:responseString]; NSDictionary *userInfo = nil; NSArray *userArr = nil; if ([returnObject isKindOfClass:[NSDictionary class]]) { if (userInfo) { [userArr release]; } userInfo = (NSDictionary*)returnObject; } else if ([returnObject isKindOfClass:[NSArray class]]) { userArr = (NSArray*)returnObject; } NSError* e = nil;
//系統自帶的解析方式。
NSDictionary * userInfo = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&e]; if (e) { NSLog(@"%@",e); }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。