convert json to object c#

Convert object to JSON C# NewtonSoft

In this post, we are going to learn how we can convert an object into JSON string in c#.

Let's explore the below examples -

Use the quickest method of converting between JSON and.NET object is using.Net Inbuilt class JsonSerializer. High performance, faster than .NET's built-in JSON serializes -

System.Web.Script.Serialization.JavaScriptSerializer jsSerializerObj = new JavaScriptSerializer();

User = new User
            {
                ID ="100023",
                Age ="29",
                FirstName = "Anil",
                LastName = "Singh"
            };

string json = jsSerializerObj.Serialize(User);

OR

Use Newtonsoft Json Convert - It allows you to create an object, populate the fields, and serialize as JSON -

var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(User);

I hope you enjoy this post.
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^