后台返回json 包含\n 解决办法

//后台不愿意给你解决的话 用此方法  
NSString * str = [[NSString alloc]initWithData:json encoding:NSUTF8StringEncoding];
        
NSString * str2 = [str stringByReplacingOccurrencesOfString:@"\t" withString:@"\\t"];
        
str2 = [str2 stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"];
        
str2 = [str2 stringByReplacingOccurrencesOfString:@"\r" withString:@"\\r"];
        
NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:[str2 dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];

你可能感兴趣的:(后台返回json 包含\n 解决办法)