NSDictionary
字典控制台打印转码,unicode转中文
//
// NSDictionary+Dlog.m
// 网络
//
// Created by chip on 2018/4/16.
// Copyright © 2018年 chip. All rights reserved.
//
#import "NSDictionary+Dlog.h"
@implementation NSDictionary (Dlog)
- (NSString *)descriptionWithLocale:(id)locale{
if (![self count]) {
return @"";
}
NSString *tempStr1 =
[[self description] stringByReplacingOccurrencesOfString:@"\\u"
withString:@"\\U"];
NSString *tempStr2 =
[tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
NSString *tempStr3 =
[[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
NSString *str =
[NSPropertyListSerialization propertyListWithData:tempData
options:NSPropertyListImmutable
format:NULL
error:NULL];
return str;
}
@end
使用:
//引头文件
NSLog(@"\ndata:%@",[dict descriptionWithLocale:nil]);
NSArray
数组控制台打印转码,unicode转中文
#import "NSArray+Dlog.h"
@implementation NSArray (Dlog)
-(NSString *)descriptionWithLocale:(id)locale{
NSMutableString *string = [NSMutableString string];
// 开头有个[
[string appendString:@"[\n"];
// 遍历所有的元素
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[string appendFormat:@"\t%@,\n", obj];
}];
// 结尾有个]
[string appendString:@"]"];
// 查找最后一个逗号
NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
if (range.location != NSNotFound)
[string deleteCharactersInRange:range];
return string;
}
@end
网友评论