Click here to Skip to main content
16,009,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me, How to read mintemp from the following json
JavaScript
"forecast":{"2019-10-12":{"date":"2019-10-12","date_epoch":1570838400,
"mintemp":29,"maxtemp":36,"avgtemp":32,"totalsnow":0,"sunhour":8.7,"uv_index":8}}}"


What I have tried:

VB
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(xUrl), HttpWebRequest)
        Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
        Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
        Dim o As JObject = JObject.Parse(reader.ReadToEnd)
        Dim fc As String = o("forecast")("date")("mintemp")
Posted
Updated 13-Oct-19 7:18am
v2

1 solution

Your JSON is probably not properly formatted, try this:
Dim o As JObject = JObject.Parse(
    "{'forecast':{'2019-10-14':{'date':'2019-10-14','date_epoch':1570838400, 'mintemp':29,'maxtemp':36,'avgtemp':32,'totalsnow':0,'sunhour':8.7,'uv_index':8}}}")

Dim fc As String = o("forecast")("2019-10-12")("mintemp").ToString()
Console.WriteLine(fc)
If you want to use the current date:
Dim fc As String = o("forecast")(DateTime.Now.ToString("yyyy-MM-dd"))("mintemp").ToString()
 
Share this answer
 
v2
Comments
sgramesh75 14-Oct-19 2:27am    
Thx for ur response.. o("forecast")("2019-10-12")("mintemp").ToString() in this date will change everyday..Reaing data from URl
RickZeeland 14-Oct-19 3:46am    
See the updated solution :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900