Read and parse JSON in C# / .NET Framework

access_time 2 years ago visibility97 comment 0

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 5 days ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Want to publish your article on Kontext?

Learn more

Kontext Column

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


Learn more arrow_forward

More from Kontext

local_offer C# local_offer .NET

visibility 37
thumb_up 0
access_time 11 months ago

This code snippet shows how to convert string to date.

Introduction to C# Interactive

local_offer C# local_offer .NET

visibility 91
thumb_up 0
access_time 5 days ago

Python, R and many other scripting languages generally support interactive programming features in their IDEs. When C# was created initially, all C# written programs need to be complied into MSIL first before it can run in .NET runtime environments (unless the code is dynamically complied).  ...

Entity Framework Core Code-First - Generate Covering Index with Columns Included

local_offer entity-framework local_offer asp.net core local_offer Azure local_offer C#

visibility 109
thumb_up 1
access_time 3 months ago

In SQL Server or some other relational databases, it is a very common requirement to create covering index with columns included in index pages beside the index key columns. With Entity Framework Core, you can also easily generate covering indexes using purely C# code. For Kontext website, backend ...

About column

Code snippets for various programming languages/frameworks.

rss_feed Subscribe RSS