none
How to read JSON data?

    Question

  • Hi,

    I am using a web service for my application. The response body of one of the query to web service is in JSON format(provided below).

    I am new to JSON. I need to read the data(ex: "name": "value") and load a class with the retrieved information. Please help.

    [
      {
        "canEdit": false,
        "name": "aggregation",
        "displayName": "Aggregation",
        "reverseName": "parent",
        "preferredEnd": true
      },
      {
        "canEdit": false,
        "name": "dependency",
        "displayName": "Depends on",
        "reverseName": "dependent",
        "preferredEnd": true
      },
      {
        "canEdit": false,
        "name": "dependent",
        "displayName": "Dependent",
        "reverseName": "dependency",
        "preferredEnd": false
      },
      {
        "canEdit": false,
        "name": "parent",
        "displayName": "Parent",
        "reverseName": "aggregation",
        "preferredEnd": false
      },
      {
        "canEdit": true,
        "name": "tutoree",
        "displayName": "Tutorial for",
        "reverseName": "tutorial",
        "preferredEnd": false
      },
      {
        "canEdit": true,
        "name": "tutorial",
        "displayName": "Tutorial",
        "reverseName": "tutoree",
        "preferredEnd": true
      }
    ]


    Ashutosh Chaturvedi

    Wednesday, February 06, 2013 6:42 AM

Answers

  • Have a look at the link

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Wednesday, February 06, 2013 6:52 AM
  • Hi,

    There are several ways you can do that. If your JSON comes from a stable API and has always the same structure, you can use DataContractJsonSerializer.

    There is also an excellent open source library Json.NET. If you are into speed, check out ServiceStack's JSON parser ServiceStack.Text.

    Cheers


    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    Wednesday, February 06, 2013 7:47 AM
  • Hi Ashutosh,

    You can simply use "Newtonsoft.Json" dll to read jason response. We have used Newtonsoft.Json.JsonConvert.DeserializeObject method to Covert your Jason response to respective Object.

    For more information of how to use this dll/method please check below links :

    http://stackoverflow.com/questions/4749639/deserializing-json-to-net-object-using-newtonsoft-or-linq-to-json-maybe

    http://www.codeproject.com/Tips/79435/Deserialize-JSON-with-C

    You can download Newtonsoft.Json from Here 

    Hope this will help you.


    If my response answered your question, please mark the response as an answer and also vote as helpful !!! - Krantikumar


    Wednesday, February 06, 2013 9:33 AM

All replies

  • Have a look at the link

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Wednesday, February 06, 2013 6:52 AM
  • Hi,

    There are several ways you can do that. If your JSON comes from a stable API and has always the same structure, you can use DataContractJsonSerializer.

    There is also an excellent open source library Json.NET. If you are into speed, check out ServiceStack's JSON parser ServiceStack.Text.

    Cheers


    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    Wednesday, February 06, 2013 7:47 AM
  • Hi Ashutosh,

    You can simply use "Newtonsoft.Json" dll to read jason response. We have used Newtonsoft.Json.JsonConvert.DeserializeObject method to Covert your Jason response to respective Object.

    For more information of how to use this dll/method please check below links :

    http://stackoverflow.com/questions/4749639/deserializing-json-to-net-object-using-newtonsoft-or-linq-to-json-maybe

    http://www.codeproject.com/Tips/79435/Deserialize-JSON-with-C

    You can download Newtonsoft.Json from Here 

    Hope this will help you.


    If my response answered your question, please mark the response as an answer and also vote as helpful !!! - Krantikumar


    Wednesday, February 06, 2013 9:33 AM