Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing JSON objects to c#

Tags:

json

c#

.net-3.5

I am trying to use the example in this link http://sharpdevpt.blogspot.com/2009/10/deserialize-json-on-c.html?showComment=1265045828773#c2497312518008004159

But my project wont compile using JavaScriptConvert.DeserializeObject, the example says this is from a .net library does anyone know which one?

I know the example below uses Newtonsoft.Json....

like image 970
van Avatar asked Feb 01 '10 17:02

van


People also ask

Can I use JSON in C?

Parsing JSON in C using microjson Developed originally for server-browser communication, the use of JSON has since expanded into a universal data interchange format. This tutorial will provide a simple introduction to parsing JSON strings in the C programming language using the microjson library.

What is JSON object in C?

JSON or JavaScript Object Notation is a lightweight text-based open standard designed for human-readable data interchange. Conventions used by JSON are known to programmers, which include C, C++, Java, Python, Perl, etc. JSON stands for JavaScript Object Notation. The format was specified by Douglas Crockford.

Does C# have a JSON parser?

Jobject. Parse() method is an object class method and this method is used to parse the JSON string into the objects of C#. Based on the key value it parses the data of string and then it retrieves the data by using the key values.

How pass data from JSON to string in C#?

JsonConvert class has a method to convert to and from JSON string, SerializeObject() and DeserializeObject() respectively. It can be used where we won't to convert to and from a JSON string. In the following example, I have used “JsonConvert. DeserializeObject” method to cast my JSONobject to my custom class object.


1 Answers

The Javascript Serializer in .NET is part of the System.Web.Script.Serialization namespace.

Here's an example extension method I use to deserialize strings:

public static T FromJSON<T>(this string json)
 {
            JavaScriptSerializer jss = new JavaScriptSerializer();

            return jss.Deserialize<T>(json);
 }

Since this is an extension method of string you can use it on any string.

MyCustomType = myJsonString.FromJSON<MyCustomType>();
like image 93
Jamie Dixon Avatar answered Oct 06 '22 02:10

Jamie Dixon