Answers for "how to print the read json values in c#"

6

c# get value from json object

using System;
using Newtonsoft.Json.Linq;

namespace testClient
{
    class Program
    {
        static void Main()
        {
            var myJsonString = "{report: {Id: \"aaakkj98898983\"}}";
            var jo = JObject.Parse(myJsonString);
            var id = jo["report"]["Id"].ToString();
            Console.WriteLine(id);
            Console.Read();
        }
    }
}
Posted by: Guest on June-11-2021
7

c# read json file into object

// read file into a string and deserialize JSON to a type
Movie movie1 = JsonConvert.DeserializeObject<Movie>(File.ReadAllText(@"c:\movie.json"));

// deserialize JSON directly from a file
using (StreamReader file = File.OpenText(@"c:\movie.json"))
{
    JsonSerializer serializer = new JsonSerializer();
    Movie movie2 = (Movie)serializer.Deserialize(file, typeof(Movie));
}
Posted by: Guest on September-29-2020

Code answers related to "how to print the read json values in c#"

Code answers related to "Javascript"

Browse Popular Code Answers by Language