Parth Doshi Parth Doshi - 4 months ago 62
JSON Question

Parse JSON String to JSON Object in C#.NET

I have a JSON String returned by my SOAP web service in .NET. It is as follows:


{"checkrecord":[{"rollno":"abc2","percentage":40,"attended":12,"missed":34}],"Table1":[]}


Now I want to parse this string to a JSON Object. I also read this where they have used this line of code:


JObject jsonObj = JObject.Parse(json);


So can I do the same by replacing "json" with my string name. Also do I need to reference any other dll except the NewtonSoft.dll ?

BTW, Here is the full webservice code

Answer

use new JavaScriptSerializer().Deserialize<object>(jsonString)

You need System.Web.Extensions dll and import the following namespace.

Namespace: System.Web.Script.Serialization

for more info MSDN