• 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
  On 27/10/2015 at 14:10, i11usive said:

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

    • Except Rolling Releases. No EOL, continuous updates.
    • True, Windows 95 could barely run on systems made in 1995. Two responses, first, people did complain in the 90s about how quickly software updates obsoleted hardware, so it isn't like it was fine then and not now. Second, it hits a little different when the requirement is seemingly arbitrary instead of a true resource requirement.
    • Go from ZERO to ADVANCED with this Microsoft Training Bundle + Office 2021 Pro Plus by Steven Parker Today's highlighted deal comes via our Online Courses section of the Neowin Deals store, where you can save 79% off Microsoft Office Pro Plus 2021 + Microsoft Training Bundle: ZERO to ADVANCED. This bundle consists of the following items: Microsoft Training Bundle: ZERO to ADVANCED LearningWhilePracticing | 6 Lessons (25h) | Lifetime $20.00 Value The Microsoft Training Bundle is the ultimate course for those looking to master Microsoft Office. With comprehensive lessons that cover Excel, Word, Access, and PowerPoint, you'll go from beginner to advanced user in no time. Learn in-demand skills like VLOOKUP and XLOOKUP in Excel, and conditional formatting to make your data stand out. With this bundle, you'll have all the tools you need to succeed in the workplace and beyond. Access 6 courses & 25 hours of content 24/7 Learn to create workbooks & spreadsheets Explore the readily available document templates Protect a file with a password & recover an unsaved document Build effective database solutions for unique data needs Create a PowerPoint presentation from scratch Create slides, textboxes & formatting text and paragraphs Perform two-dimensional lookups Discover how to calculate & highlight expiration dates What’s Included Microsoft Excel: from ZERO to ADVANCED Microsoft Word: from ZERO to ADVANCED Microsoft Access: from ZERO to ADVANCED Microsoft PowerPoint: from ZERO to ADVANCED VLOOKUP & XLOOKUP in Excel Conditional Formatting in Excel Good to know Length of time users can access this course: lifetime Access options: desktop & mobile Redemption deadline: redeem your code within 30 days of purchase Experience level required: beginner Updates included Certificate of Completion ONLY Microsoft Office Pro Plus 2021: Lifetime License One time digital license | $219.99 Value Everything a pro needs, all in one suite — that’s Microsoft Office 2021 Professional. Microsoft Office 2021 Professional is the perfect choice for any professional who needs to handle data and documents. It comes with many new features that will make you more productive in every stage of development, whether it’s processing paperwork or creating presentations from scratch – whatever your needs are! Good to know ONE-TIME PURCHASE FOR 1 PC Redemption deadline: redeem your code within 30 days of purchase This is NOT compatible with MS Office on Parallels Pro and other Virtual Machines Access options: desktop No subscriptions – no monthly/annual fees Version: Office 2021 Pro All languages supported Updates included Here's the deal: This Microsoft Office Pro Plus 2021 + Microsoft Training Bundle: ZERO to ADVANCE bundle normally costs $239.99, but you can get it for just $49.99 for a limited time - that's a saving of $189 or 79% off. For a full description, specs, and instructor info, click the link below. Get Office 2021 Pro + Office Training Bundle deal for just $49.99, or learn more Although priced in U.S. dollars, this deal is available for digital purchase worldwide. We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • This article is about older builds of Windows 11 losing support, there have been no system requirements changes for any version of Windows 11. You were probably talking about Windows 10...but that is a an off-topic comment.
    • Only if you install an LTS version. The non-LTS distros of Linux typically have much shorter support cycles than Windows. If you are the kind of person who, for whatever reason, doesn't want to move to newer builds, simply "install linux" would make it worse, not better.
  • Recent Achievements

    • Week One Done
      Stephen Leibowitz earned a badge
      Week One Done
    • Week One Done
      Homayoun Hotak earned a badge
      Week One Done
    • Dedicated
      Profit earned a badge
      Dedicated
    • One Month Later
      hhgygy earned a badge
      One Month Later
    • Week One Done
      hhgygy earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      640
    2. 2
      ATLien_0
      240
    3. 3
      Xenon
      169
    4. 4
      neufuse
      151
    5. 5
      +FloatingFatMan
      124
  • Tell a friend

    Love Neowin? Tell a friend!