JSON 在UITextView显示格式化

NSString *jsonString = _requestStr;
    
NSError *error = nil;
    
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    
NSData *jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:nil error:&error];
NSData *prettyJsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:&error];
  
NSString *pretyPrintedJsonStr = [[NSString alloc] initWithData:prettyJsonData encoding:NSUTF8StringEncoding];
 
NSString *formatJsonStr = [pretyPrintedJsonStr stringByReplacingOccurrencesOfString:@"\\" withString:@""];

你可能感兴趣的:(JSON 在UITextView显示格式化)