https://stackoverflow.com/questions/47457268

VbNet · Console

/Program.vb

Imports System
Imports Newtonsoft.Json.Linq
				
Public Module Module1
	Public Sub Main()

            Dim json As String =
                "{" +
                "  ""result"": {" +
                "    ""a326f402f18ab1cd2c4489b07cc3e8f4"": {" +
                "      ""id"": ""a326f402f18ab1cd2c4489b07cc3e8f4""," +
                "      ""client_id"": 30," +
                "      ""broker"": [" +
                "        {" +
                "          ""broker_id"": 30," +
                "          ""name"": ""Andrew""," +
                "          ""emailaddress"": ""[email protected]""" +
                "        }" +
                "      ]," +
                "      ""photos"": [" +
                "        {" +
                "          ""small"": ""https://www.example.com/30/photos/small/66.1427790195-976.jpg""," +
                "          ""middle"": ""https://www.example.com/30/photos/middle/66.1427790195-976.jpg""" +
                "        }," +
                "        {" +
                "          ""small"": ""https://www.example.com/30/photos/small/31382.1508417843-454.JPG""," +
                "          ""middle"": ""https://www.example.com/30/photos/middle/31382.1508417843-454.JPG""" +
                "        }" +
                "      ]" +
                "    }," +
                "    ""18aec266ec0c01d126e9715bc17124e2"": {" +
                "      ""id"": ""18aec266ec0c01d126e9715bc17124e2""," +
                "      ""client_id"": 30," +
                "      ""broker"": [" +
                "        {" +
                "          ""broker_id"": 30," +
                "          ""name"": ""Andrew""," +
                "          ""emailaddress"": ""[email protected]""" +
                "        }" +
                "      ]," +
                "      ""photos"": [" +
                "        {" +
                "          ""small"": ""https://www.example.com/30/photos/small/10.1298385655.jpg""," +
                "          ""middle"": ""https://www.example.com/30/photos/middle/10.1298385655.jpg""" +
                "        }," +
                "        {" +
                "          ""small"": ""https://www.example.com/30/photos/small/10.1298385646.jpg""," +
                "          ""middle"": ""https://www.example.com/30/photos/middle/10.1298385646.jpg""" +
                "        }" +
                "      ]" +
                "    }" +
                "  }" +
                "}"
		
            Dim obj As JObject = JObject.Parse(json)
            Dim result As JObject = DirectCast(obj("result"), JObject)
            For Each prop As JProperty In result.Properties()
		
                Dim item As JObject = DirectCast(prop.Value, JObject)
                Dim id As String = item("id").Value(Of String)
                Dim clientId As Integer = item("client_id").Value(Of Integer)
                Console.WriteLine("id: " & id)
                Console.WriteLine("client id: " & clientId.ToString())
		
                Dim brokers As JArray = DirectCast(item("broker"), JArray)
                For i As Integer = 0 To brokers.Count - 1
					Dim broker As JObject = DirectCast(brokers(i), JObject)
                   	Dim brokerId As Integer = broker("broker_id").Value(Of Integer)
                   	Dim name As String = broker("name").Value(Of String)
                   	Dim email As String = broker("emailaddress").Value(Of String)
                    Console.WriteLine("broker " & i.ToString() & " id: " & brokerId)
                    Console.WriteLine("broker " & i.ToString() & " name: " & name)
                    Console.WriteLine("broker " & i.ToString() & " email: " & email)
                Next
	
                Dim photos As JArray = DirectCast(item("photos"), JArray)
                For i As Integer = 0 To photos.Count - 1
                    Dim photo As JObject = DirectCast(photos(i), JObject)
                    Dim small As String = photo("small").Value(Of String)
                    Dim middle As String = photo("middle").Value(Of String)
                    Console.WriteLine("photo " & i.ToString() & " small: " & small)
                    Console.WriteLine("photo " & i.ToString() & " middle: " & middle)
                Next

                Console.WriteLine()
            Next

	End Sub
End Module
;