iOS解析JSON字符串报错Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 586."

将服务器返回的JSON string转化成字典时报错:

Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 586."

仔细查找后在原来解析的基础上将"\"字符替换成""或"\\"后,解析成功。具体的解析代码如下:

- (NSDictionary *)parseJsonStringToNSDictionary:(NSString *)jsonString
{

    jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
    jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\t" withString:@""];
    jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\\" withString:@""];

    NSError *error2=nil;
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&error2];
    if ([dict isValid]) {
        return dict;
    }
    return nil;
}
时间: 2024-10-13 08:33:38

iOS解析JSON字符串报错Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 586."的相关文章

error = Error Domain=NSCocoaErrorDomain Code=3840

json解析,同样的请求,有一个请求,无反应.纠结了几天,终于解决了. error = Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character around character 168." UserInfo={NSDebugDescription=Unescaped control character around character 168.} 报错信息如上: 这个原因,是因为服务器返回的字符串里面

Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage at end.}

1.\0 导致JSON无法解析的问题,把\0替换成@""即可. 1 NSString *string = @"{\n\t\"responseType\":\t-1\n}\0"; 2 NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; 3 4 NSError *error = nil; 5 NSDictionary *dictionary = [NSJSONSerializ

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)"

AF解析json出错: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn't be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8a8a700 {NSDebugDescription=JSON te

Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授权字符串" UserInfo=0x17426e940 {NS

注册远程通知是报错 Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的"aps-environment"的授权字符串" UserInfo=0x17426e940 {NSLocalizedDescription=未找到应用程序的"aps-environment"的授权字符串} 1. 在X-code中更新证书: Xcode > Preferences > Accounts > pi

CoreData____.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "T

使用coreData存储数据的时候,运行app就报错CoreData____.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn't be completed. (Cocoa error 134100.)". 解决办法:把模拟器里面的原来的app删除就可以了.运行OK.

Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的权利字符串" UserInfo=0x1bad30 {NSLocalizedDescription=未找到应用程序的“aps-environment”的权利字符串}

Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的权利字符串" UserInfo=0x1bad30 {NSLocalizedDescription=未找到应用程序的“aps-environment”的权利字符串} code =3000 App ID 和 Bundle Identity不匹配.

蓝牙4.0收发数据 报Error Domain=CBErrorDomain Code=0 这个错

不小心改了一个地方结果一直报一个错Error Domain=CBErrorDomain Code=0, 后来和之前的对比了一下,发现是UUID导致的错误 看红色部分,是由于改变了UUID导致的 2015-05-28 17:05:32.034 bluetoothDemo[704:71315] didWriteValueForCharacteristic <CBCharacteristic: 0x146aa0f0, UUID = FFF2, properties = 0x8, value = (nu

【解决方法】Error Domain=kCLErrorDomain Code=0 &quot;The operation couldn’t be completed.

环境:XCODE6.0.1 + iPhone / iOS8 错误:使用CoreLocation获取地理位置信息,报错 Error Domain=kCLErrorDomain Code=0 "The operation couldn't be completed. (kCLErrorDomain error 0.)" 解决方法: 1.确定模拟器(手机)已经联网并且允许程序获取地理位置 2.重置地理位置服务或者网络服务 PS:如果是模拟器就果断直接重置模拟器吧  IOS Simulator

ios奇葩问题 Error Domain=NSURLErrorDomain Code=-1003

问题描述: 新上线的产品,ios同事拿着一串报错来找我,日志如下:err =Error Domain=NSURLErrorDomain Code=-1003 "未能找到使用指定主机名的服务器.",接口中请求的域名为app.xxx.com(xxx.com隐藏). 安卓手机,自带网络,访问域名app.xxx.com正常 安卓手机,Wifi网络,访问域名app.xxx.com正常 电脑,访问域名app.xxx.com正常 ios手机,Wifi网络,访问域名app.xxx.com正常 ios手