read JSON file

  • Thread starter Thread starter khattabcosmology
  • Start date Start date
K

khattabcosmology

Guest
Good Evening,

I'm trying to read a JSON file in VB.net,

the results is not complete.

this is the JSON example:

{
"Passes":
{
"Areas":
[
{
"id":28646,
"PassTimes":
[
{
"gap":-1,
"from":22343.766438359,
"to":22343.7664384495,
"UTCfrom":"04.03.2019 18:23:40",
"UTCto":"04.03.2019 18:23:40",
"rms":9.04219632502645E-8
}
]
}
]
}
,

{
"id":33412,
"PassTimes":
[
{
"gap":-1,
"from":22343.145140881,
"to":22343.1451409714,
"UTCfrom":"04.03.2019 3:29:00",
"UTCto":"04.03.2019 3:29:00",
"rms":9.04256012290716E-8
}
]
}
]
}


}

And this is my code:


Imports System.IO
Imports Newtonsoft.Json.Linq
Imports Newtonsoft.Json
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim STR As StreamReader
STR = New StreamReader(filename.json")


Dim rawresp As String
rawresp = STR.ReadToEnd()

Dim jo = Newtonsoft.Json.Linq.JObject.Parse(rawresp)


Dim VidID1 = jo("Passes")("Areas")(0)("id")
Dim VidID2 = jo("Passes")("Areas")(0)("PassTimes")(0)("UTCfrom")
Dim VidID3 = jo("Passes")("Areas")(0)("PassTimes")(0)("UTCto")

ListBox1.Items.Add(VidID1)
ListBox1.Items.Add(VidID2)
ListBox1.Items.Add(VidID3)

the only output i get is the first values:


"id":28646,
"UTCfrom":"04.03.2019 18:23:40",
"UTCto":"04.03.2019 18:23:40",

And in case of using array i get an error,

For Each item As JObject In array

"The error is : Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject


Please, i need your advise and help,


Thanks,

Khaled

Continue reading...
 

Similar threads

Back
Top