• 0

Nested JSON data


Question

I want to consume the following JSON data structure using a VB.NET handler. The handler is working on the root keys - how do I deal with Sub > Sub-1, Sub > Sub-2, Another-Sub > Sub-3

{
    "ID": id,
    "ParentId": parentId,
    "Sub":
        [{
           "Sub-1":
                [{
                   "Data":"Test",
                   "MoreData":"MoreTestData"
                }],
            "Sub-2":
                [{
                   "Data":"Test 2",
                   "MoreData":"More Test Data 2"
                }],
        }],
    "Another-Sub":
        [{
           "Sub-3":
                [{
                   "Data":"Test 2",
                   "MoreData":"More Test Data",
                   "EvenMoreDate":"Even More Data"
                }],
           "Sub-4":
                [{
                   "Data":"Test 2",
                   "MoreData":"More Test Data",
                   "EvenMoreDate":"Even More Data"
                }],
        }],
}

 

My Handler code is as follows:

Dim js As New JavaScriptSerializer()
    Dim data As DataClass = js.Deserialize(Of DataClass)(json)
    
    Public Class DataClass
        Public Property ID() As String
            Get
                Return _ID
            End Get
            Set(value As String)
                _ID = value
            End Set
        End Property
        Private _ID As String

        etc etc
        
    End Class

    Public Class Sub
        Public Property Data() As String
    End Class



How can I access tier 2 / 3 json data?

All help appreciated - hopefully I've described my issue satisfactorily.

 

 

 

Link to comment
https://www.neowin.net/forum/topic/1276388-nested-json-data/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Hi,

There are a plethora of ways to work with JSON on multi-levels, however you'll really want to add JSON.NET (Website Link) or similar to your application and utilise that library rather than "hacking" at it with a JavaScriptSerializer.
This will give you an easy way of serialising/deserialising and even implementing LINQ-To-JSON.

Enjoy!

  • 0

Thanks Kami .. I was a little reluctant to use a third party solution seeing as there is support within the framework. I'll have a look and see if that helps any.

Appreciate the response.

Newtonsoft has been a standard .NET library for at least the last year or two.

 

This is a standard web api project:

 

Capture.PNG

Edited by adrynalyne
This topic is now closed to further replies.
  • Posts

    • I'd say the first one failed to be as popular as Apple anticipated, but the easy adjustment here is to make fewer of them next time around. It would only be a "flop" if it isn't possible for Apple to recover the design and factory tooling costs given the number of units sold, which I doubt would be the case. It isn't like no one bought them; it just failed to become the new hot phone of the year.
    • You're right that it does not follow the plain meaning of the word, but in this context, it is a legal term defined in 49 U.S.C. Kind of how "wire fraud" laws apply even if a physical wire was not used. Given that it is codified in law, and it isn't just automotive journalists that don't understand evolving technology, I highly doubt congress would change a well understood term just because technology makes the term slightly less actuate.
    • This is exactly why I keep saying we are not ready for human free self-driving. These little "bugs" are may seem like random one-offs. There was also the Waymo that drove between police with drawn weapons and the suspect they were pointing them at. From a software perspective it is easy to understand how those extremely rare situations may not have been programed for, but that is the point. If AI needs to be told to watch out for every possible contingency, then it can never be successful. There will always be the possibility of a first encounter that the AI needs to understand to avoid.
    • TeraCopy 4.0 Final by Razvan Serea TeraCopy is a compact program designed to copy and move files at the maximum possible speed, also providing you with a lot of features. Copy files faster. TeraCopy uses dynamically adjusted buffers to reduce seek times. Asynchronous copy speeds up file transfer between two physical hard drives. Pause and resume transfers. Pause copy process at any time to free up system resources and continue with a single click. Error recovery. In case of copy error, TeraCopy will try several times and in the worse case just skips the file, not terminating the entire transfer. Interactive file list. TeraCopy shows failed file transfers and lets you fix the problem and recopy only problem files. Shell integration. TeraCopy can completely replace Explorer copy and move functions, allowing you work with files as usual. TeraCopy is free for non-commercial use only. For commercial use you need to buy a license. The paid version of the program includes the following features: Copy/move to your favorite folders. Save reports as HTML and CSV files. Select files with the same extension/folder. Remove the selected files from the copy queue. Download: TeraCopy 4.0 | 14.6MB (Freeware, paid upgrade available) View: TeraCopy Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      Eurosoft10 earned a badge
      Week One Done
    • One Month Later
      Eurosoft10 earned a badge
      One Month Later
    • One Year In
      Skeet Campbell earned a badge
      One Year In
    • One Month Later
      Sharbel earned a badge
      One Month Later
    • First Post
      BizSAR earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      586
    2. 2
      +Edouard
      187
    3. 3
      Michael Scrip
      74
    4. 4
      PsYcHoKiLLa
      72
    5. 5
      neufuse
      69
  • Tell a friend

    Love Neowin? Tell a friend!