Java中的Pretty-Print JSON [英] Pretty-Print JSON in Java
本文介绍了Java中的Pretty-Print JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 json-simple 我需要漂亮地打印JSON数据(使其更具人性化)。
I'm using json-simple and I need to pretty-print JSON data (make it more human readable).
我无法在该库中找到此功能。
这是如何实现的?
I haven't been able to find this functionality within that library. How is this commonly achieved?
推荐答案
GSON 可以很好地做到这一点:
GSON can do this in a nice way:
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(uglyJSONString);
String prettyJsonString = gson.toJson(je);
这篇关于Java中的Pretty-Print JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文