Home > DeveloperSection > Forums > How to get the values from list of objects in c#
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    March-26-2014 3:59 AM

 C# C# 
Ratings:


 1 Reply(s)
 923  View(s)
Rate this:

I have Called a Json Web Service and got the result in c#.The Json Web service data is available in format:

 {

  "Count": 9862,

  "Items": [

    {

      "Admin": {

        "S": "false"

      },

      "UserId": {

        "S": "e9633477-978e-4956-ab34-cc4b8bbe4adf"

      },

      "Age": {

        "N": "76.24807963806055"

      },

      "Promoted": {

        "S": "true"

      },

      "UserName": {

        "S": "e9633477"

      },

      "Registered": {

        "S": "true"

      }

    },

    {

      "Admin": {

        "S": "false"

      },

      "UserId": {

        "S": "acf3eff7-36d6-4c3f-81dd-76f3a8071bcf"

      },

      "Age": {

        "N": "64.79224276370684"

      },

      "Promoted": {

        "S": "true"

      },

      "UserName": {

        "S": "acf3eff7"

      },

      "Registered": {

        "S": "true"

      }

    },

I have got the Response like this in c#:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:8000/userdetails");

        try

        {

            WebResponse response = request.GetResponse();

            using (Stream responseStream = response.GetResponseStream())

            {

                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);

                return reader.ReadToEnd();

            }

        }

after finally successfully get the response i have got all the Data in string. and then parse this string in list of objects .Now I have list of objects where it showing the count in debugging.Now I want to access the values like UserId:acf3eff7-36d6-4c3f-81dd-76f3a8071bcf like properties.I dont know how to do it.

Please help me and any help will be appreciated.



Pravesh Singh

Total Post:411

Points:2881
Posted on    March-26-2014 4:33 AM

Hi Manoj,

You can use the following code to get the values from json as:

        JObject obj = JObject.Parse(json);

        int count = (int)obj["Count"];

        var Items = obj["Items"];

        foreach (var item in Items)

    var admin = item["Admin"];


Don't want to miss updates? Please click the below button!

Follow MindStick