Read and parse JSON in C# / .NET Framework
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 5 years ago
copyright
This page is subject to Site terms.
comment Comments
No comments yet.