当我的jsonstring中的字符%EF%BF%BF的内容时,JSONKit objectFromJSONString返回nil

时间:2016-01-23 10:48:26

标签: ios

+ (void)testResponseStr
{
NSString *responseString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"error_json" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
NSDictionary *destDic = [responseString objectFromJSONString];
NSLog(@"%@",responseString);
if (destDic) {
    NSLog(@"success");
}else{
    NSLog(@"error"); 
}
}

我正在尝试解析从服务器获取的json字符串,但是当json字符串的内容为charactor"" ," destDic"来自" objectFromJSONString"将是零。为什么?我如何修复JSONKit中的错误。

error_json.txt中的字符串:

{"result":{"hasMore":true,"newestWorksList":[{"hasLiked":false,"hasCollected":false,"tlName":"No smoking","likeCount":1,"title":"No smoking","authorNickname":"","commentCount":0,"uid":"69nbNm","createTime":1453539369000,"id":2546522,"createTimeStr":"2016.01.23","tlIsUserUpload":false}]},"code":0}

1 个答案:

答案 0 :(得分:0)

您可以使用:

NSString * responseString = [responseString    stringByReplacingOccurrencesOfString:@“”withString:@“”];

这不是可靠的解决方案,但现在可能适合您