JsonEncoder.withIndent(' ').convert([data]) 可以很方便的规范化输出json输出,withIndent表示每个json层级前的占位符,例如: 层级一: 1x占位 , 层级二:2x占位
使用
Map<String,String> map = {'title':'标题','content':'内容'};
String json = JsonEncoder.withIndent(' ').convert(map);
print(json);
输出
{
"title": "标题",
"content": "内容"
}