• 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

    • I wonder what $99 Chinese cellphone this phone will be based on. Whoever is dumb enough to buy the phone and/or get this service deserves everything they get.
    • Trump is a low-class guy who thinks painting everything in gold makes him look fancy.
    • Don't forget second season pass, that's not part of the superdeluxe edition.
    • Forza Motorsport gets IndyCar, Career mode improvements, and more by Taras Buria Turn 10 Studios announced the next Forza Motorsport update, which includes new content and various game improvements. Update 21 follows the previous Anniversary Update and adds IndyCar, a free expansion for Career mode, Featured Tours, new reward cars, and more. IndyCar is back in the game, allowing you to get behind the wheel of the latest-generation open-wheel racing cars. New vehicles include the 2025 Chevrolet IndyCar and the 2025 Honda IndyCar. There is also the all-new IndyCar Series in Featured Multiplayer. Career mode now has the Champions Cup, a new home for racecar-focused tours in single-player racing. There, you can drive a variety of modern and classic racecars from one-make series to endurance legends. Completing the Champions Cup will give you various high-reward cars like the 1979 BMW #6 BMW Motorsport M1 Procar, the 1998 Nissan #23 Pennzoil NISMO Skyline GT-R, the 2014 Dodge #93 SRT Motorsports Viper GTS-R, and more. Developers also adjusted the in-game pricing for most racecars to make the Champions Cup more accessible. Another change in Update 21 is the return of previous Featured Tours. The game will feature an additional Tour every month, allowing you to earn some of the previous reward cars and participate in the now-ended events. Here is a brief overview of other changes and improvements: Featured Multiplayer has been reorganized, incorporating player feedback, with the goal of providing players with even more event variety. Click here for a rundown of these changes. We’ve implemented BoP Spec changes to the Forza GT2, Forza GT3, Forza Touring Car, and Forza Proto-H divisions with help from participants in the Forza Insiders Program. See the release notes for an overview of the adjustments that have been made. The Challenge Hub menu has been reorganized to more effectively communicate where rewards can be earned as well as the type of rewards available to unlock. We’ve fixed an issue for players using the Fanatec DD2 racing wheel that would assign the peripheral an incorrect mapping profile. All Builders Cup Tours are now immediately unlocked, which means you no longer need to complete the Modern Tour to access the 3 other Builders Cup Tours. In addition, select Builders Cup Series have been updated to feature additional eligible cars and post-launch tracks. A detailed overview of these changes has been included in the release notes. There are also numerous fixes to AI behavior and competitiveness in single-player racing. You can read more about Forza Motorsport Update 21 in a post on the official Forza website.
    • If it ever gets to a reasonable level of parity, I think more real competition in the Windows space would be a good thing. What I like about this is that it's not just another reskinned Linux distro (with all of those inherent problems). It's meant to literally boot and work like Windows NT+. That could be an interesting development one day -- note that this has been in development since 1996, btw.
  • Recent Achievements

    • Explorer
      treker_ed went up a rank
      Explorer
    • Apprentice
      CHUNWEI went up a rank
      Apprentice
    • Veteran
      1337ish went up a rank
      Veteran
    • Rookie
      john.al went up a rank
      Rookie
    • Week One Done
      patrickft456 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      642
    2. 2
      ATLien_0
      274
    3. 3
      +FloatingFatMan
      173
    4. 4
      Michael Scrip
      156
    5. 5
      Steven P.
      139
  • Tell a friend

    Love Neowin? Tell a friend!