简体   繁体   English

如何在 Visual Studio Community 2019 中格式化 JSON 文档?

[英]How can I format JSON document in Visual Studio Community 2019?

I tried Ctrl + K , Ctrl + D , but it only works for *.cs files.我试过Ctrl + KCtrl + D ,但它只适用于 *.cs 文件。 JSON file has no errors and it isn't big, but when I press Ctrl + K , Ctrl + D it says the command is unavailable. JSON文件没有错误,也不大,但是当我按Ctrl + KCtrl + D时,它说命令不可用。 I tried some other combos that I've found in the internet but they don't work at all.我尝试了一些我在互联网上找到的其他组合,但它们根本不起作用。 I also don't have text editor options for JSON.我也没有 JSON 的文本编辑器选项。 Do I have to install something additionally for them to appear?我是否必须额外安装一些东西才能出现?

I have Visual Studio Community 2019 16.4.4 and Windows 10 x64.我有 Visual Studio Community 2019 16.4.4 和 Windows 10 x64。

If I understood your question, Ctrl + A , Ctrl + K + F works for me.如果我理解你的问题, Ctrl + ACtrl + K + F对我有用。

Before formatting:格式化前:
格式化前

After formatting:格式化后:
格式化后

You could copy your code into a blank JSON file using the menus.您可以使用菜单将代码复制到空白 JSON 文件中。 I'm using Microsoft Visual Studio Community 2019 Version 16.8.5.我正在使用 Microsoft Visual Studio Community 2019 版本 16.8.5。

File -->New-->File-->Web-->JSON File文件-->新建-->文件-->Web-->JSON文件

在此处输入图像描述

在此处输入图像描述

Then you can right click and choose Format Document.然后您可以右键单击并选择格式化文档。

在此处输入图像描述

None of the above worked for me.以上都不适合我。

Instead反而

ALT + SHIFT + F

did the job!完成了任务!

Ctrl + K , Ctrl + D is short key for formatting code in Visual Studio, but you need to have a web module (such as Node.js or ASP.NET) installed to format JSON. Ctrl + K , Ctrl + D是 Visual Studio 中格式化代码的快捷键,但是你需要安装一个 web 模块(例如 Node.js 或 ASP.NET)来格式化 JSON。

Modify or Installing Components in Visual Studio 在 Visual Studio 中修改或安装组件

Visual Studio 组件

首先 CTRL+E 然后按 D 键。

Ctrl+K, Ctrl+D works for me in VS2019 My file has the .json extension. Ctrl+K,Ctrl+D 在 VS2019 中适用于我我的文件具有 .json 扩展名。 I'm using Json.Net in my project as well.我也在我的项目中使用 Json.Net。

If you're having problems, there are a few packages you could import to do it through code .如果您遇到问题,您可以通过代码导入一些包来解决问题。 See:看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 Launch.json 传递 arguments 以在 Visual Studio 2019 中进行调试 - How can I pass arguments via Launch.json for debugging in Visual Studio 2019 如何将 StringContent() 类型转换为类型的对象<MyModelClass>在 C# 中使用 Visual Studio 2019 - How can I convert a StringContent() type to an object of type <MyModelClass> in C# with Visual Studio 2019 launch.json args字段中的Visual Studio Community 2017空间 - Visual Studio Community 2017 spaces in launch.json args field Visual Studio Code 中的 Json 文件结构/格式 - Json files structure/format in Visual Studio Code 如何将我自己的错误消息和智能感知添加到visual-studio-code 中的JSON 文件中 - how can I add my own error messagess and intellisense to a JSON file in visual-studio-code 如何让Visual Studio 2013使用自定义JSON模式? - How can I get Visual Studio 2013 to use a custom JSON schema? 如何让Visual Studio获取高亮.json源代码? - How can I get Visual Studio to source highlight .json source code? 如何美化文档中的 JSON? - How can I beautify JSON inside a document? 如何在JavaScript中建立JSON格式? - How can i build this json format in javascript? 如何在Android中使用这种格式创建Json? - How can I create Json with this format in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM