任何美化嵌套 NSDictionary 结果的工具
Any tools to beautify the nested NSDictionary result
有没有什么工具,包括在线服务和macOs app,可以美化这样嵌套的NSDictionary
结果?
{
id = 1;
testName = my name;
createDate = 20021023;
likeNumber = 0;
statusList = ({
appleId = 1;
orangeName = 81;
itsStatus = YES;
});
text = test;
type = Text;
},
我的意思是轻松折叠(关闭和打开)树节点。
目前,在 JSON
方面,有许多用于此目的的在线工具,例如 jsonformatter。
如 Fonix 所述,将 NSDictionary
转换为 JSON
然后使用 JSON
工具的最佳方法:
+(NSString *)dictionaryToJson:(NSDictionary *)dictionary {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
NSString *jsonString;
if (! jsonData) {
NSLog(@"Got an error: %@", error);
jsonString = [error localizedDescription];
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}
有没有什么工具,包括在线服务和macOs app,可以美化这样嵌套的NSDictionary
结果?
{
id = 1;
testName = my name;
createDate = 20021023;
likeNumber = 0;
statusList = ({
appleId = 1;
orangeName = 81;
itsStatus = YES;
});
text = test;
type = Text;
},
我的意思是轻松折叠(关闭和打开)树节点。
目前,在 JSON
方面,有许多用于此目的的在线工具,例如 jsonformatter。
如 Fonix 所述,将 NSDictionary
转换为 JSON
然后使用 JSON
工具的最佳方法:
+(NSString *)dictionaryToJson:(NSDictionary *)dictionary {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
NSString *jsonString;
if (! jsonData) {
NSLog(@"Got an error: %@", error);
jsonString = [error localizedDescription];
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}