如何从使用 Visual Studio 的 Web Essentials 创建的 class 中获取 JSON

How to get JSON from a class, created using Visual Studio's Web Essentials

中所述,我正在 C# 和 JSON 中设置我的第一步。

我正在开发一个小型应用程序,它可以从数据库中读取信息并将其写入 JSON 文件中。为此,我考虑创建 classes,因为它们在 JSON 文件中定义。为此,我使用了 Web Essentials,它做得很好:classes 已完全生成。所有这些都在我之前的问题中提到过。

现在我想用那些classes回写到JSON文件,所以我有这样的情况:

JSON file1 : used as an input in order to create the class diagram.
DB         : contains some information I need to add to the JSON file.
JSON file2 : used as an output, based on "JSON file1", and having the extra information, retrieved from the DB.

显然很天真,我已经这样做了:

root.ToString(); // hoping that this would generate the JSON output.

但是,我似乎只能从该方法中获得一些基本信息(命名空间和 class名称,无内容)。

使用智能感知,我没有看到任何生成我的 JSON 输出的方法,但我的代码(由 Web Essentials 生成的代码)中有一种希望,如您所见:

    public class Rootobject
    {
        public Project project { get; set; }
    }

    public class Project
    {
        public string commonDESCRIPTION { get; set; }
        ...
        public Location[] locations { get; set; }

如您所见,RootobjectProject 都没有继承自任何东西(它们也没有实现接口),我简直不敢相信没有任何 class涵盖这种行为。所以,我想知道我需要继承哪个 class 来解决这个问题。
但是,我认为这可能不是那么容易,也许需要进行一些 Web Essentials 配置编辑才能涵盖这一点,但我不知道如何修改 Visual Studio 扩展配置。

编辑
有关我的 Web Essentials 安装的更多信息:在我的 Visual Studio 2017 Enterprise 平台上安装 Web Essentials 后,我可以看到 Paste SpecialPaste JSON 在我的 Edit 菜单中显示为 classes,但我在菜单中看不到 Web Essentials工具栏(仅文件编辑、...)和工具选项 我也没有看到任何 Web Essentials 参考资料。

有人可以帮我吗?
提前致谢

显然(如Ruan所述),Web Essentials可以将JSON文件转换为class模型,但在另一个方向上,必须遵循另一种方式。

提到的方法(NewtonSoft),非常好:

  • 添加“NewtonSoft”作为参考(我使用 NuGet 包管理器做到了)。
  • 在源码开头加入using Newtonsoft.Json;.
  • 到JSON的转换很简单:string result = JsonConvert.SerializeObject(root);.