How to get the values from list of objects in c#

Total Post:154

Points:1086
C# 
C#
 1651  View(s)
Ratings:
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.

  1. Post:412

    Points:2888
    Re: How to get the values from list of objects in c#

    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"];

      Modified On Apr-04-2018 04:42:04 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!