Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json Serialization in C# [closed]

I'm trying to serialize a local object to json but msdn documentation always seems to confuse me. I believe I am suppose to use the DataContractJsonSerializer but not completely sure, as I have seen mixed responses. I've also had someone recommend Newtonsoft.

Does anyone have any experience with this that can point me in the right direction?

like image 414
Brandon Clapp Avatar asked Nov 07 '12 21:11

Brandon Clapp


People also ask

What is JSON serialization?

Serialization is the process of converting . NET objects such as strings into a JSON format and deserialization is the process of converting JSON data into . NET objects.

Why do we need JSON serialization?

The purpose of serializing it into JSON is so that the message will be a format that can be understood and from there, deserialize it into an object type that makes sense for the consumer.

Does JSON serialize data?

The json module exposes two methods for serializing Python objects into JSON format. dump() will write Python data to a file-like object. We use this when we want to serialize our Python data to an external JSON file. dumps() will write Python data to a string in JSON format.


1 Answers

You could use the JavaScriptSerializer.

http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

var thing = new Thing(); var json = new JavaScriptSerializer().Serialize(thing); 
like image 145
Chris Farmer Avatar answered Sep 28 '22 10:09

Chris Farmer