问题描述
对于Web API,我总是使用ASP.NET,但现在我正在进行一些增强,所以我开始学习MVC 4来创建Web API。问题是在ASP.NET中我总是使用一类对象来序列化/反序列化JSON参数。
现在在MVC中用于序列化我不需要创建一个class,我可以默认将响应设置为JSON,但是我想知道是否有任何方法可以在MVC 4中反序列化JSON post参数而不创建任何类,那么MVC 4是否有办法解决这个问题?
For web API I always use ASP.NET but now I'm doing some enhancement so i started learning MVC 4 to create a Web API. The problem is that in ASP.NET I always used a class of objects to serialize/deserialize JSON parameters.
now in MVC for serialization I do not need to create a class, I can make the response to be JSON by default, but I'm wondering if there is any way to deserialize the JSON post parameters in MVC 4 also without creating any class, so is there a way MVC 4 handle this?
推荐答案
using System.Web.Script.Serialization;
JavaScriptSerializer oJS = new JavaScriptSerializer();
RootObject oRootObject = new RootObject();
oRootObject = oJS.Deserialize<RootObject>(Your JSon String);
这篇关于在mvc 4 vb.net中反序列化Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!