Click here to Skip to main content
15,881,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 14-Mar-14 5:47am
v2

Hope the example give you some idea:
XML
using System.Web.Script.Serialization;

JavaScriptSerializer oJS = new JavaScriptSerializer();
RootObject oRootObject = new RootObject();
oRootObject = oJS.Deserialize<RootObject>(Your JSon String);
 
Share this answer
 
Hi Jocelyne El Khoury528

Import using this
using System.Web.Script.Serialization;


example
string jsonstring = "[a:'abc', b:'def']";

JavaScriptSerializer objJS = new JavaScriptSerializer();
(if you dont import JavaSciptSerializer, write above line anf resolve this by right click it will automatically add namespace of using)

ObjectType obj = new ObjectType();
obj = oRootObject = objJS.Deserialize<objecttype>(jsonstring);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900