iOS 去除JSON裡的轉義字元
//iOS 去除JSON裡的轉義字元
// 首先將返回格式設為二進位制格式
manager.responseSerializer = [AFHTTPResponseSerializerserializer];
// 其次第一種方法去除轉義字元
NSString * str = [[NSStringalloc]initWithData:responseObjectencoding:NSUTF8StringEncoding];
NSMutableString * responseString = [NSMutableStringstringWithString
NSString *character = nil;
for (int i =0; i < responseString.length; i ++) {
character = [responseString substringWithRange:NSMakeRange(i,1)];
if ([character isEqualToString:@"\\"])
[responseString deleteCharactersInRange
}
NSData * data = [responseStringdataUsingEncoding:NSUTF8StringEncoding];
NSDictionary * dataDic = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];
// 第二種方法去除轉義字元
NSString * str = [[NSStringalloc
str = [str stringByReplacingOccurrencesOfString:@"\r\n"withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"\n"withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"\t"withString:@""];
// str = [str stringByReplacingOccurrencesOfString:@"\\" withString:@""];
NSData * data = [strdataUsingEncoding:NSUTF8StringEncoding];
NSDictionary * dataDic = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];