By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .

JSON is commonly used in modern applications for data storage and transfers. Pretty much all programming languages provide APIs to parse JSON. 

There are many libraries you can use in .NET/C# to parse JSON content.

Json.NET (Newtonsoft.Json) is one of the commonly used library. The package information is available on the following page:

https://www.nuget.org/packages/Newtonsoft.Json

Code snippet

using Newtonsoft.Json;
using System;

namespace ConsoleApp1
{
    class Program
    {
        public class MyType
        {
            public string Name { get; set; }
            public int Value { get; set; }
        }
        static void Main(string[] args)
        {
            var jsonStr = "{\"Name\":\"A\",\"Value\":2}";
            Console.WriteLine(jsonStr);
            var jsonObj = JsonConvert.DeserializeObject(jsonStr);
            Console.WriteLine(jsonObj.Name);
            Console.WriteLine(jsonObj.Value);
            Console.ReadLine();
        }
    }
}
info Last modified by Raymond at 11 months ago * This page is subject to Site terms.

More from Kontext

local_offer csharp local_offer dotnet

visibility 19
thumb_up 0
access_time 5 months ago

This code snippet shows how to convert string to date.

open_in_new View open_in_new Code snippets

info About author

Dark theme mode

Dark theme mode is available on Kontext.

Learn more arrow_forward
Kontext Column

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.

Learn more arrow_forward
info Follow us on Twitter to get the latest article updates. Follow us