iOS json字符串转字典
2019-10-29 本文已影响0人
tongyuling
一、先去掉转移‘/’
NSMutableString *responseString = [NSMutableString stringWithString:@"xxxxxxx"];
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)];
}
二、转字典
NSData *jsonData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];