json解析出现错误

碰到这样的错误:JSONValue failed. Error is: Unescaped control character [0x09] //ps:用SBJson才会有这个提示,系统方法不会提示错误

有如下解决方案:
//去除未转义的控制字符
-(NSString *)removeUnescapedCharacter:(NSString *)inputStr
{

NSCharacterSet *controlChars = [NSCharacterSet controlCharacterSet];

NSRange range = [inputStr rangeOfCharacterFromSet:controlChars];

  if (range.location != NSNotFound) 
  {

      NSMutableString *mutable = [NSMutableString stringWithString:inputStr];

      while (range.location != NSNotFound) 
      {

          [mutable deleteCharactersInRange:range];

          range = [mutable rangeOfCharacterFromSet:controlChars];

      }

      return mutable;

   }

  return inputStr;
}


//你可以这样调用 Call this method with passing your output string like this
NSString *output = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"yourUrlString"] encoding:NSUTF8StringEncoding error:nil];

output = [self removeUnescapedCharacter:output];

posted on 2014-01-22 10:45  金玉游龙  阅读(513)  评论(0编辑  收藏  举报

导航