locked
Nested Json Deserialization to C# object and using that object RRS feed

  • Question

  • User-1438206782 posted

    HI All,

               i have the following scenario where nested json to n-level.

    example: 

    "aggregations":{
          "assetClassFacet":{
             "buckets":[
                {
                   "key":"image",
                   "doc_count":6,
                   "mixedFacet":{
                      "buckets":[
                         {
                            "key":"mix",
                            "doc_count":6
                         }
                      ]
                   }
                },
                {
                   "key":"document",
                   "doc_count":4,
                   "mixedFacet":{
                      "buckets":[
                         {
                            "key":"mix",
                            "doc_count":4
                         }
                      ]
                   }
                },
                {
                   "key":"video",
                   "doc_count":1,
                   "mixedFacet":{
                      "buckets":[
                         {
                            "key":"mix",
                            "doc_count":1
                         }
                      ]
                   }
                }
             ]
          },
          "contentCategory":{
             "buckets":[
                {
                   "key":"credits",
                   "doc_count":1
                },
                {
                   "key":"misc",
                   "doc_count":1
                },
                {
                   "key":"storyboards",
                   "doc_count":1
                }
             ]
          }
       }

    In the above json string "assetClassFacet" first level, " mixedFacet" is child to the previous one, like this it can go to N-level.

    Im using Newtonsoft.Json dll for my project. Im able get jObject but dont know how can i loop or get the information wat i required in some class format.

    Please help.

    Thanks in Advance.

    Friday, June 20, 2014 11:34 AM

Answers

  • User1176121428 posted

    Hi vasu,

    Thanks for your post.

    The quickest method of converting between JSON text and a .NET object is using the JsonSerializer. The JsonSerializer converts .NET objects into their JSON equivalent and back again by mapping the .NET object property names to the JSON property names and copies the values for you.

    Here is a good artilce about Serializing and Deserializing JSON

    If you have any issues,I suggest that you can post your issue to C# Forum for professional response

    Hope this helps u.

    Best Regards,

    Eileen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 22, 2014 11:27 PM

All replies

  • User-1552614833 posted

    Use this tool  this you will get class based on json 

    http://json2csharp.com/

    Friday, June 20, 2014 11:40 AM
  • User-1438206782 posted

    Thank you,

    May be im not clear what im expecting. Let me elaborate.

    I cant the above mentioned tool as i dont required class, instead i require kine of parent child relationship dictionries for n level with recursively loop through my json string.

    Thanks

    Friday, June 20, 2014 11:46 AM
  • User1176121428 posted

    Hi vasu,

    Thanks for your post.

    The quickest method of converting between JSON text and a .NET object is using the JsonSerializer. The JsonSerializer converts .NET objects into their JSON equivalent and back again by mapping the .NET object property names to the JSON property names and copies the values for you.

    Here is a good artilce about Serializing and Deserializing JSON

    If you have any issues,I suggest that you can post your issue to C# Forum for professional response

    Hope this helps u.

    Best Regards,

    Eileen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 22, 2014 11:27 PM