Since there is no JavaScriptSerializer, what native implementation can be used to handle this?

我注意到JsonResult,我可以用它将数据格式化为JSON,但是我如何反序列化呢?

Or maybe I am missing some dependencies in project.json?

推荐答案

You can use Newtonsoft.Json, it's a dependency of Microsoft.AspNet.Mvc.ModelBinding which is a dependency of Microsoft.AspNet.Mvc. So, you don't need to add a dependency in your project.json.

#using Newtonsoft.Json
....
JsonConvert.DeserializeObject(json);

注意,使用WebAPI控制器不需要处理JSON.

更新ASP.NET Core 3.0

Json.NET已从ASP.NET Core 3.0共享框架中删除.

您可以在高性能Utf8JsonReaderUtf8JsonWriter之上使用新的JSON序列化器层.它从JSON反序列化对象,并将对象序列化为JSON.内存分配保持最小,并支持异步读取和写入JSON流.

To get started, use the JsonSerializer class in the System.Text.Json.Serialization namespace. See the documentation for information and samples.

To use Json.NET in an ASP.NET Core 3.0 project:

    services.AddMvc()
        .AddNewtonsoftJson();

Read Json.NET support in Migrate from ASP.NET Core 2.2 to 3.0 Preview 2 for more information.

Json相关问答推荐

json输入(嵌套数组)和输出需要jolt规范

使用jq解析多层json

在PowerShell中,如何获取数据对所在的JSON对象的名称

使用PowerShell解析文件并获取特定行的值

使用快速json库编写json可以消除所有缩进

使用 Powershell,如何将 Azure AD 组成员转换为 Json 对象(文件),然后可以更新?

如何将具有相同 struct 的多个JSON文件中的对象数组合并成一个数组?

使用 jolt 将对象数组转换为数组

JSON 的自定义编组器,可以是字符串或 map[string]string / map[string]bool

如何将 JSON 文本作为参数传递给 powershell?

无法使用 vue.js 访问 JSON 数组的项目

JOLT JSON 将值从一对多转换为一对一

jq搜索特定字符串并输出对应的父值

C# 合并 2 个几乎相同的 JSON 对象

可以通过 POST 使用 EventSource 传递参数的服务器发送事件 (SSE)

jQuery fullcalendar 发送自定义参数并使用 JSON 刷新日历

如何在 swift 2 中获取 Alamofire.request().responseJSON 的结果值?

POST:在 url 本身中发送 post 请求

C++:使用 nlohmann json 从文件中读取 json 对象

将 JsonArray 添加到 JsonObject