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
?
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.
Json.NET已从ASP.NET Core 3.0共享框架中删除.
您可以在高性能Utf8JsonReader
和Utf8JsonWriter
之上使用新的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.