在ASP JSON序列化/反序列化。网络核心

时间:2022-09-15 12:59:00

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

既然没有JavaScriptSerializer,那么可以使用什么本地实现来处理这个问题呢?

I noticed JsonResult and I can format data to Json with this, but how do I deserialize?

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

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

或者可能我在project.json中漏掉了一些依赖项?

1 个解决方案

#1


104  

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.

您可以使用Newtonsoft。Json是Microsoft.AspNet.Mvc的一个依赖项。是Microsoft.AspNet.Mvc的一个依赖项。因此,不需要在project.json中添加依赖项。

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

Note, using a WebAPI controller you don't need to deal with JSON.

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

#1


104  

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.

您可以使用Newtonsoft。Json是Microsoft.AspNet.Mvc的一个依赖项。是Microsoft.AspNet.Mvc的一个依赖项。因此,不需要在project.json中添加依赖项。

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

Note, using a WebAPI controller you don't need to deal with JSON.

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