iPhone开发笔记(22)-JSONValue Failed. Error is : Unescaped control character的解决方法

    在利用json-framework来实现json解析的过程时,会出现"-JSONValue Failed. Error is : Unescaped control character"的错误。这种问题一般是由转义字符引起的,这些转义字符可能是因为web服务编写时造成的,也可能是其它原因导致的。解决这一问题的关键代码如下。

NSString *jsonString = [[request responseString] stringByReplacingOccurrencesOfString:@"\r" withString:@""];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\s" withString:@""];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\t" withString:@""];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\v" withString:@""];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\f" withString:@""];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\b" withString:@""];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\a" withString:@""];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\e" withString:@""];

    经过处理后的字符串再调用方法[jsonString JSONValue]来进行解析。

你可能感兴趣的:(json解析,转义字符)