Eclipse中的 Ctrl + Shift + F 热键可以格式化文件。它不适用于.json
个文件。如何使它工作?
答案 0 :(得分:16)
如果你还没有它,你会想要获得JSON编辑器插件。你可以找到它here
JSON编辑器是Eclipse IDE的一个简单插件,它提供: - 颜色文本突出显示 - 大纲树视图 - JSON验证 - 文本格式化 - JSON数据格式的文本折叠。
如果热键仍然无效。看看菜单下的菜单,如其网站here
中的图片所示此外,我发现过去至少存在一个与当前版本格式化功能有关的问题。 从他们的讨论site:
rlespinola
2010-07-15 00:18:05 UTC
Using version 0.9.4, I do not see the option to "Format Text". Also, when I open a .json file, the outline view says "An outline is not available".
jdschulteis
2010-12-27 16:59:24 UTC
Using 0.9.4 on Helios, I also had "An outline is not available". I went to Window->Preferences->General->Editors->File Associations, selected '*.json' in the 'File types:' list, selected 'Json Editor' in the 'Associated editors:' list, and clicked 'Default'. I now get an outline, though it can be somewhat slow (6K line file).
修改强>
有几种方法可以添加插件。 Eclipse建议使用update manager。 试试help > software updates > find and install
您可以查看here的其他替代方法。
答案 1 :(得分:5)
我使用Eclipse Luna(4.4.0)找到了两个选项。
使用JSON编辑器插件并定义快捷方式
将Javascript开发插件与丑陋且令人讨厌的解决方法一起使用
{"addressbook": {"name": "John Doe",
"address": {
"street": "5 Main Street", "city": "San Diego, CA", "zip": 91912
},
"phoneNumbers": [
"619 555-3452",
"664 555-4667"
]
}
}

var obj = {"addressbook": {"name": "John Doe",
"address": {
"street": "5 Main Street", "city": "San Diego, CA", "zip": 91912
},
"phoneNumbers": [
"619 555-3452",
"664 555-4667"
]
}
}

答案 2 :(得分:4)
您可以使用Eclipse附带的JavaScript编辑器。