Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15571

VS 2019 Iiterate any json sring

$
0
0
I'm trying to loop through this string but it stops right after the array.

Here is the JSON String
Code:

[
      {
        "@context": "http://schema.org",
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "item": {
              "@id": "https://www.site.com/",
              "name": "Home",
              "image": null
            }
          },
          {
            "@type": "ListItem",
            "position": 2,
            "item": {
              "@id": "https://www.site.com/recipes/",
              "name": "Recipes",
              "image": null
            }
          },
          {
            "@type": "ListItem",
            "position": 3,
            "item": {
              "@id": "https://www.site.com/recipes/80/main-dish/",
              "name": "Main Dish Recipes",
              "image": null
            }
          },
          {
            "@type": "ListItem",
            "position": 4,
            "item": {
              "@id": "https://www.site.com/recipes/258/main-dish/roasts/",
              "name": "Roast Recipes",
              "image": null
            }
          }
        ]
      },
      {
        "@context": "http://schema.org",
        "@type": "Recipe",
        "mainEntityOfPage": "https://www.site.com/recipe/56352/garlic-prime-rib/",
        "name": "Garlic Prime Rib",
        "image": {
          "@type": "ImageObject",
          "url": "https://imagesvc.site.io/v3/mm/image?url=https%3A%2F%2FFuserphotos%2F6036515.jpg",
          "width": null,
          "height": null,
          "caption": "Garlic Prime Rib"
        }
]

and the code
Code:

Dim res As JToken = JToken.Parse(RTBJson.Text)
Select Case res.Type
                Case 1
                Case 2 ' we start with an array
                 
                    CollectItems(res.Item(0))
end select
 Sub CollectItems(ByVal jToken As JToken)
       
Select Case jToken.Type
            Case JTokenType.Object
                MessageBox.Show(jToken.Count.ToString)
              For Each child In jToken.Children(Of JProperty)()
                    CollectItems(child)
                Next             

            Case JTokenType.Array

                For Each child In jToken.Children().ToList
                    CollectItems(child)
                Next

            Case JTokenType.[Property]             
                Me.GetCase(jToken)
                ' Next
        End Select
    End Sub

messagebox says there is only 3 items. how do I get it to see all of it? What am I missing?

Viewing all articles
Browse latest Browse all 15571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>