有谁知道让 moshi 生成带缩进的多行 json 的方法(供人类在 config.json 的上下文中使用) 所以来自:
{"max_additional_random_time_between_checks":180,"min_time_between_checks":60}
像这样:
{
"max_additional_random_time_between_checks":180,
"min_time_between_checks":60
}
我知道其他 json-writer 实现可以这样做 - 但我想在这里坚持使用 moshi 以保持一致性
最佳答案
现在您可以在适配器上使用 .indent("")
方法进行格式化。
final Moshi moshi = new Moshi.Builder().build();
String json = moshi.adapter(Dude.class).indent(" ").toJson(new Dude())
关于java - 使用 moshi 格式化 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35026581/