I'm using Newtonsoft.JSon.Linq and at this point im kinda confused about how to make things work in the way i need it for my project. In order to jump into topic heres what im doing or at least want to do.
I want to extract the JSon data into structures based on the second level of the JSon nodes for a JSon which has this structure:
{
"country" : {
"germany" : {
"capital" : "berlin",
"inhabitants_in_million" : 82,
"zip-codes" : [
[
"berlin",
10115
],
[
"hamburg",
21145
],
[
"munich",
80331
]
]
},
"france" : {
"capital" : "paris",
"inhabitants_in_million" : 67,
"zip-codes" : [
[
"paris",
75001
],
[
"marseille",
13000
]
]
}
}
My Structure so far is like that so far:
Public countries As List(Of country)
Public Structure country
Public name As String
Public capital As String
Public inhabtitants As Integer
End Structure
And im using this code to read the data of the JSon:
Private Sub json_sub()
For Each n In json_object
For Each n_2 As JProperty In n.Value
Dim c As New country
c.name = n_2.Name
c.capital = json_object.SelectToken("country").SelectToken(n_2.Name).SelectToken("capital")
c.inhabtitants = json_object.SelectToken("country").SelectToken(n_2.Name).SelectToken("inhabitants_in_million")
countries.Add(c)
Next
Next
End Sub
But im somehow struggling with the data serialized in [] since its an array and all my attempts so far did not work off. I browsed for quite some time and read about deserializiation but unfortunately im kinda stuck at this point now.
My goal is to add the values from this arrays into a string which should look like:
berlin,10115;hamburg,21145;munich,80331
So I can add this string to my structure country with
Public zip_codes As String
Instead of using an array which is unhandy in my project at this point. I hope anyone can get me suggestion how i can achieve this.
Sincerly, boon