Hello – having a little trouble extracting the “obs” array data from this json:
{“serial_number”:“AR-00013631”,“type”:“obs_air”,“hub_sn”:“HB-00000761”,“obs”:[[1545240091,1007.40,5.91,67,0,0,3.39,1]],“firmware_revision”:20}
I think the double square brackets may be the issue. I don’t know how to get rid of them. This json stream comes in via a UDP broadcast message from a weather station. Here is the code I’m using:
Dim jsonDict As Xojo.Core.Dictionary = Xojo.Data.ParseJSON(str(TextField1.Text).ToText)
Dim resultsArray( ) As Auto
If
jsonDict.Lookup("type", "---") = "obs_air" then
Dim obs_air_pressure_v As Integer
Dim obs_air_pressure As String
Dim obs_air_temp_v As Integer
Dim obs_air_temp As String
resultsArray( ) = jsonDict.Value("obs")
obs_air_pressure_v = resultsArray(2)
obs_air_pressure = str(obs_air_pressure_v)
obs_air_temp_v = resultsArray(3)
obs_air_temp = str(obs_air_temp_v)
TextField2.Text = obs_air_pressure
TextField3.Text = obs_air_temp
else
end
I’m doing the same for another json broadcast message from the same weather station and it works fine – note this one does not have double square brackets :
{“serial_number”:“SK-00004809”,“type”:“rapid_wind”,“hub_sn”:“HB-00000761”,“ob”:[1545240171,0.76,258]}
the code:
If
jsonDict.Lookup("type", "---") = "rapid_wind" then
Dim rapid_wind_speed_v As Integer
Dim rapid_wind_speed As String
Dim rapid_wind_dir_v As Integer
Dim rapid_wind_dir As String
resultsArray( ) = jsonDict.Value("ob")
rapid_wind_speed_v = resultsArray(1)
rapid_wind_speed = str(rapid_wind_speed_v)
rapid_wind_dir_v = resultsArray(2)
rapid_wind_dir = str(rapid_wind_dir_v)
TextField2.Text = rapid_wind_speed
TextField3.Text = rapid_wind_dir
else
end
I think with the only difference in the json structure being double brackets in one (not working) and single square brackets in the other (working) leads me to think that the extra brackets are the issue. Any Ideas to get rid of them would be a great help. Or if there is something else I’m missing.
Thanks
JP