iOS 解析带/的JSON字符串

先去掉转移符/

1
2
3
4
5
6
7
8
9

NSMutableString *responseString = @"{\"cate\":\"2\",\"share_url\":\"http://api.fafaasfaijia.com/fd/notifdce_detail.html?notisdssdsce_id=18&\",\"id\":\"18\"}";
NSString *character = nil;
for (int i = 0; i < responseString.length; i ++) {
character = [responseString substringWithRange:NSMakeRange(i, 1)];
if ([character isEqualToString:@"\\"])
[responseString deleteCharactersInRange:NSMakeRange(i, 1)];
}
NSLog(@"%@",responseString);

将JSON字符串转化为字典

1
2
3
4
5
6
7
8
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {

if (jsonString == nil) {

return nil;
}
NSData *jsonData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];