How to display json data in console application in c#

Program.cs



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            JavaScriptSerializer obj = new JavaScriptSerializer();
            string str = File.ReadAllText("json.json");
                Employee oblemp=obj.Deserialize<Employee>(str);
                Console.WriteLine("Employee Number = "+oblemp.ID +" Employee Name ="+oblemp.Name);
                Console.ReadLine();
        }
    }
    public class Employee
    {
        public string Name { get; set; }
        public int ID { get; set; }
    }
}



json.json



{
"Name":"srinivas",
"ID":1
}

Comments

Popular posts from this blog

Reverse Sentence using c#

How to write Pure java script Program?