国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

IOS json 解析遇到錯(cuò)誤問題解決辦法

2020-07-26 02:58:33
字體:
供稿:網(wǎng)友

概要:

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的時(shí)候都是標(biāo)準(zhǔn)格式,json數(shù)據(jù)當(dāng)中沒有 /n /r /t 等制表符。

今天在解析的時(shí)候發(fā)現(xiàn)json解析時(shí)好時(shí)壞,用在線json解析也米有問題。找了半天終于發(fā)現(xiàn)是制表符在作怪,由于標(biāo)準(zhǔn)的json解析是不允許有這幾個(gè)制表符的。所以在收到保溫的時(shí)候我們需要把這幾個(gè)制表符給過濾掉。

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;

//系統(tǒng)自帶的解析方式。

NSDictionary * userInfo = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:&e];if (e) {NSLog(@"%@",e);}

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 湟中县| 炉霍县| 磐石市| 灯塔市| 台南市| 会东县| 贵德县| 镶黄旗| 黄浦区| 辛集市| 洪湖市| 盈江县| 年辖:市辖区| 五原县| 铜梁县| 玛多县| 天镇县| 博客| 贞丰县| 平潭县| 石柱| 黑山县| 台江县| 广西| 元江| 民和| 巴林左旗| 廊坊市| 彭水| 锡林郭勒盟| 灌南县| 湘潭市| 龙山县| 新兴县| 开阳县| 伊通| 紫阳县| 苏尼特右旗| 聂荣县| 凤庆县| 洛扎县|