My program accesses data through a Web API and gets data in JSON format. Response is for example:
{
"response":{
"stationId":"24026900",
"prices":[
{
"name":"Aral Super E10",
"price":"146,90",
"currency":"EUR",
"id":"001131",
"sort":"21"
},
{
"name":"Aral Super 95",
"price":"152,90",
"currency":"EUR",
"id":"001040",
"sort":"22"
},
{
"name":"Aral Ultimate 102",
"price":"172,90",
"currency":"EUR",
"id":"001255",
"sort":"24"
},
{
"name":"Aral Diesel",
"price":"130,90",
"currency":"EUR",
"id":"004002",
"sort":"30"
},
{
"name":"Aral Ultimate Diesel",
"price":"150,90",
"currency":"EUR",
"id":"004267",
"sort":"31"
},
{
"name":"Aral LKW Diesel",
"price":"130,90",
"currency":"EUR",
"id":"004010",
"sort":"32"
}
],
"lastUpdate":"202104122030",
"disabled":"false",
"openNow":"Wir haben f\u00fcr Sie ge\u00f6ffnet."
}
}
How can I e.g. access deeply nested data like "price":"172,90".
My structure is like:
Dim sJSON As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim PriceLastValue As String = funcGetPriceInfo("response") 'How to get access to deeper nested data here?
'
'Every key except "response" throws an exception
'
MsgBox(PriceLastValue.ToString)
End Sub
Private Function funcGetPriceInfo(ByVal sVal As String) As String
Dim JSONSerializer As New System.Web.Script.Serialization.JavaScriptSerializer
sJSON = ReadStreamFromWeb.ReadFileFromWeb_WebRequest("http://ap.aral.de/api/v2/getStationPricesById.php?stationId=24026900")
Dim dictJSON As Dictionary(Of String, Object) = JSONSerializer.Deserialize(Of Dictionary(Of String, Object))(sJSON)
Return dictJSON(sVal).ToString
End Function
thank you, really appreciate your help! Now added reference to Newtonsoft and the classes:
And trying to get the object:
But this throws..