【发布时间】:2011-11-24 09:41:45
【问题描述】:
Eclipse 中的 Ctrl + Shift + F 热键可以格式化文件。它不适用于.json 文件。如何让它发挥作用?
【问题讨论】:
标签: json eclipse formatting indentation auto-indent
Eclipse 中的 Ctrl + Shift + F 热键可以格式化文件。它不适用于.json 文件。如何让它发挥作用?
【问题讨论】:
标签: json eclipse formatting indentation auto-indent
我使用 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"
]
}
}
【讨论】:
Choose "Format Text" and set the "When:" value to "Editing Text"
您可以使用 Eclipse 附带的 JavaScript 编辑器。
【讨论】:
如果您还没有 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 以了解一些替代方法。
【讨论】:
json,我用过, ctrlshiftf ,它格式化输出,但整个代码是黑白的。没有颜色是非常困难的。如何解决这个问题