用于 Eclipse 的 JSON 格式化程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30591686/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:56:00  来源:igfitidea点击:

JSON Formatter for Eclipse

jsoneclipseformatter

提问by pseudoCoder

I want to format the JSON files in my eclipse on save file action, based on number of spaces that i can configure. I tried using JSON Editor Plugin but it gave me null pointer exception on saving.

我想根据我可以配置的空间数在保存文件操作时格式化 Eclipse 中的 JSON 文件。我尝试使用 JSON 编辑器插件,但它在保存时给了我空指针异常。

Error on saving with Json Editor PluginThen i tried JSON Tools plugin and it worked but it used a tab for formatting the lines. Is there any hack that i can do with plugin jar to configure and change TAB to 4 spaces? Are better json formatter available for eclipse?

Error on saving with Json Editor Plugin然后我尝试了 JSON 工具插件,它工作了,但它使用了一个选项卡来格式化行。我可以使用插件 jar 来配置并将 TAB 更改为 4 个空格吗?是否有更好的 json 格式化程序可用于 Eclipse?

回答by l__j

Have you tried Json Tools for Eclipse? It is handy and lightweight Eclipse plugin. I have checked this right now and it works as you want - if there are TABs in a modified JSON file, they are changed to 4 spaces.

您是否尝试过Eclipse 的 Json 工具?它是一个方便且轻量级的 Eclipse 插件。我现在已经检查过了,它可以按您的意愿工作 - 如果修改后的 JSON 文件中有 TAB,它们将更改为 4 个空格。

You can find it in Marketplaceor install it using update site:

您可以在Marketplace 中找到它或使用更新站点安装它:

https://bitbucket.org/denmiroch/jsontools/src/default/JsonSite/

回答by Robert Fey

Some other extensions adhere to the preference set for the general text editor.

其他一些扩展遵循通用文本编辑器的首选项设置。

If it doesn't clash with other settings you can try:

如果它不与其他设置冲突,您可以尝试:

General -> Appearance -> Editors -> Text Editors

常规 -> 外观 -> 编辑器 -> 文本编辑器

[x] Insert spaces for tabs

[x] 为制表符插入空格

回答by Rick Riemer

As of Eclipse 4.6 (Neon) a JSON Editor is included in the Eclipse IDE for Java EE Developers.

从 Eclipse 4.6 (Neon) 开始,面向 Java EE 开发人员的 Eclipse IDE 中包含一个 JSON 编辑器。

回答by UdayKiran Pulipati

To change any file to open in default editor Goto Eclipse Menu Window -> General -> Editors -> File Associations

要更改任何文件以在默认编辑器中打开,请转到 Eclipse 菜单窗口 -> 常规 -> 编辑器 -> 文件关联

You will see lots of File Typessection available, Select the filein File TypesSection, In Associated editorssection you will find most available editors to open the file.

您将看到许多可用的文件类型部分,在文件类型部分中选择文件,在关联的编辑器部分中,您将找到大多数可用的编辑器来打开文件。

Select Any editor and click on Defaultbutton to open file in default editorwindow.

选择任何编辑器并单击默认按钮以在默认编辑器窗口中打开文件。

Example View:Eclipse File Associations

示例视图:Eclipse File Associations