如何在 .netcore class 库中解析 JSON

How to parse JSON in a .netcore class library

我正在使用 .NET 核心 class 库项目模板创建跨平台库,需要使用 JSON 与 REST 服务通信。

我无法使用 JSON.NET Nuget 包或 "System.Runtime.Serialization.Json",因为这些包都不支持 .netcore。

出于遗留原因以及 netstandard1.2,我也以 net40 为目标。

您可以使用 Newtonsoft.Json。

或者,您可以在 Swagger format and use AutoRest 中为其编写元数据,以自动为您生成代理 class。在内部,AutoRest 生成的代码使用 Newtonsoft.Json 进行 json 序列化。