8959,黄花闺女的来历99%都不知道,错点王妃
概要:
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); }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
网友评论