java 格式化Json字符串intellij?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40244386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Format Json Strings intellij?
提问by User4506837
I am developing Java using intellij idea. And I want to assign a json like format to a Java String. But I am tired with escape characters that I have to deal with.
我正在使用 Intellij 想法开发 Java。我想将类似 json 的格式分配给 Java 字符串。但是我厌倦了必须处理的转义字符。
Is there any easy tool to format without escape characters?
有没有什么简单的工具可以在没有转义字符的情况下进行格式化?
回答by Supun Wijerathne
You can use inject languagefeature.
您可以使用注入语言功能。
Ex:
前任:
String myJsonString = "";
- Place cursor between " and ".
- Alt+ Enter-> Inject language or reference -> select jsonfrom the dropdown appears,
- Now you have injected json to that String. Again Alt+ Enter-> Edit Json Fragment.
- Now you can give your json inside pop-up tool as a normal json, Intellij will convert it as a String with escape characters for you. :))
- 将光标置于“和”之间。
- Alt+ Enter-> 注入语言或参考 ->从出现的下拉列表中选择json,
- 现在您已将 json 注入到该字符串中。再次Alt+ Enter-> 编辑 Json 片段。
- 现在,您可以将 json 内部弹出工具作为普通 json 提供,Intellij 会将其转换为带有转义字符的字符串。:))
Refer official documentationfor more info.
有关更多信息,请参阅官方文档。
回答by NiVeR
For anyone that is using STS (Spring Tool Suite) and generally Eclipse the escape feature can be enabled by checking the checkbox under:
对于使用 STS(Spring Tool Suite)和一般 Eclipse 的任何人,可以通过选中以下复选框启用转义功能:
Preferences -> Java -> Editor -> Typing -> Escape text when pasting into a string literal
首选项 -> Java -> 编辑器 -> 输入 -> 粘贴到字符串文字时转义文本
after this just define a String and paste the json
content and the IDE will take care of the escaping.
在此之后只需定义一个字符串并粘贴json
内容,IDE 将负责转义。