31

I receive the following Json through a web service:

  {
     report: {
      Id: "aaakkj98898983"
     }
  }

I want to get value of the Id. How to do this in C#? THANKS

3
  • 2
    What have you looked into? I mean, you know, there are several articles on using JSON in .Net... Commented May 9, 2013 at 10:06
  • 2
    You need to show some research effort before asking a question. What have you already tried? Commented May 9, 2013 at 10:06
  • Next time try to find an answer on your own before you ask a question Commented May 9, 2013 at 10:25

1 Answer 1

93

First, download Newtonsoft's Json Library, then parse the json using JObject. This allows you to access the properties within pretty easily, like so:

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();
        }
    }
}   
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.