Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert object to JSON without JSON.NET library?

I want to save this object:

Student s = new Student();

to Json file. But Visual Studio 2012 can't find none of these namespaces:

System.Web.Script;
System.Json;
System.Runtime.Serialization.Json;

Any idea?

like image 512
gkiko Avatar asked Mar 28 '13 23:03

gkiko


2 Answers

If you want to serialize class into Json you can try this one too:

Install JSON.NET if you haven't yet.

make sure to include using Newtonsoft.Json;

and you can try this code:

Student s = new Student();
string json = JsonConvert.SerializeObject(s);

sorry for my bad english.

like image 63
Jilberta Avatar answered Oct 23 '22 14:10

Jilberta


Step 1: Google "System.Runtime.Serialization.Json Namespace" and find this page:

System.Runtime.Serialization.Json Namespace

Step 2: Click on the class you are interested in ( let's say JsonReaderWriterFactory Class )

Step 3: Read the part that says what assembly that class is in:

Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)

Step 4: Add that DLL as a reference to your project. See: How to: Add or Remove References By Using the Add Reference Dialog Box

Step 5: Repeat Steps 1 - 4 as needed.

like image 26
Christopher Painter Avatar answered Oct 23 '22 13:10

Christopher Painter