dar*_*sky 1 iphone objective-c json-framework ios sbjson
我正在为iOS使用SBJson框架(也称为json-framework).
解析某个JSON文件时,我收到以下错误: -JSONValue失败.错误是:未转义的控制字符[0x09] '
我已经多次使用过这个框架,我也在同一个应用程序中解析一个非常相似的JSON文件(甚至更长),并且它工作正常.
我试着扔掉一堆NSLog,一切似乎都很好.有人可以指出这个错误意味着什么,或者至少如何继续调试这样的错误?
以下是显示错误的代码:
- (void)downloadSchedule:(NSString *)jsonString {
// Get JSON feed URL and instantiate a dictionary object with its content
NSDictionary *topDic = [jsonString JSONValue];
NSLog(@"topDic count %d", [topDic count]);
Run Code Online (Sandbox Code Playgroud)
topDic显示的计数为0.错误在该[jsonString JSONValue]行.
谢谢
我有一个很好的解决方案.应用此方法删除转义字符.
-(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;
}
Run Code Online (Sandbox Code Playgroud)
像这样传递输出字符串来调用此方法
NSString *output = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"yourUrlString"] encoding:NSUTF8StringEncoding error:nil];
output = [self removeUnescapedCharacter:output];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3918 次 |
| 最近记录: |