Hello,
I need a small help or an example. I have a small section in my App where I want to show the live Weather plus weather conditions for the next 3 days. I am using accuweather for this.
I am getting the following json data response.
Using the https://b4x.com:51041/json/index.html
I get the following output:
I am not sure how to use the above as I would like to parse the data separately and then show them on labels as Day 1, Day 2 and Day 3 etc as shown in the below image
I need a small help or an example. I have a small section in my App where I want to show the live Weather plus weather conditions for the next 3 days. I am using accuweather for this.
I am getting the following json data response.
B4X:
{
"Headline": {
"EffectiveDate": "2022-08-15T08:00:00+02:00",
"EffectiveEpochDate": 1660543200,
"Severity": 5,
"Text": "A thunderstorm Monday",
"Category": "thunderstorm",
"EndDate": "2022-08-15T20:00:00+02:00",
"EndEpochDate": 1660586400,
"MobileLink": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?unit=c&lang=en-us",
"Link": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?unit=c&lang=en-us"
},
"DailyForecasts": [
{
"Date": "2022-08-11T07:00:00+02:00",
"EpochDate": 1660194000,
"Temperature": {
"Minimum": {
"Value": 16.1,
"Unit": "C",
"UnitType": 17
},
"Maximum": {
"Value": 28.1,
"Unit": "C",
"UnitType": 17
}
},
"Day": {
"Icon": 2,
"IconPhrase": "Mostly sunny",
"HasPrecipitation": false
},
"Night": {
"Icon": 33,
"IconPhrase": "Clear",
"HasPrecipitation": false
},
"Sources": [
"AccuWeather"
],
"MobileLink": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=1&unit=c&lang=en-us",
"Link": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=1&unit=c&lang=en-us"
},
{
"Date": "2022-08-12T07:00:00+02:00",
"EpochDate": 1660280400,
"Temperature": {
"Minimum": {
"Value": 17.5,
"Unit": "C",
"UnitType": 17
},
"Maximum": {
"Value": 28.3,
"Unit": "C",
"UnitType": 17
}
},
"Day": {
"Icon": 1,
"IconPhrase": "Sunny",
"HasPrecipitation": false
},
"Night": {
"Icon": 33,
"IconPhrase": "Clear",
"HasPrecipitation": false
},
"Sources": [
"AccuWeather"
],
"MobileLink": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=2&unit=c&lang=en-us",
"Link": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=2&unit=c&lang=en-us"
},
{
"Date": "2022-08-13T07:00:00+02:00",
"EpochDate": 1660366800,
"Temperature": {
"Minimum": {
"Value": 18.3,
"Unit": "C",
"UnitType": 17
},
"Maximum": {
"Value": 28.1,
"Unit": "C",
"UnitType": 17
}
},
"Day": {
"Icon": 2,
"IconPhrase": "Mostly sunny",
"HasPrecipitation": false
},
"Night": {
"Icon": 33,
"IconPhrase": "Clear",
"HasPrecipitation": false
},
"Sources": [
"AccuWeather"
],
"MobileLink": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=3&unit=c&lang=en-us",
"Link": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=3&unit=c&lang=en-us"
},
{
"Date": "2022-08-14T07:00:00+02:00",
"EpochDate": 1660453200,
"Temperature": {
"Minimum": {
"Value": 19.9,
"Unit": "C",
"UnitType": 17
},
"Maximum": {
"Value": 29.3,
"Unit": "C",
"UnitType": 17
}
},
"Day": {
"Icon": 3,
"IconPhrase": "Partly sunny",
"HasPrecipitation": false
},
"Night": {
"Icon": 36,
"IconPhrase": "Intermittent clouds",
"HasPrecipitation": false
},
"Sources": [
"AccuWeather"
],
"MobileLink": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=4&unit=c&lang=en-us",
"Link": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=4&unit=c&lang=en-us"
},
{
"Date": "2022-08-15T07:00:00+02:00",
"EpochDate": 1660539600,
"Temperature": {
"Minimum": {
"Value": 16.6,
"Unit": "C",
"UnitType": 17
},
"Maximum": {
"Value": 23.9,
"Unit": "C",
"UnitType": 17
}
},
"Day": {
"Icon": 4,
"IconPhrase": "Intermittent clouds",
"HasPrecipitation": true,
"PrecipitationType": "Rain",
"PrecipitationIntensity": "Moderate"
},
"Night": {
"Icon": 35,
"IconPhrase": "Partly cloudy",
"HasPrecipitation": false
},
"Sources": [
"AccuWeather"
],
"MobileLink": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=5&unit=c&lang=en-us",
"Link": "http://www.accuweather.com/en/de/hemer/58675/daily-weather-forecast/174476?day=5&unit=c&lang=en-us"
}
]
}
Using the https://b4x.com:51041/json/index.html
I get the following output:
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim Headline As Map = jRoot.Get("Headline")
Dim Category As String = Headline.Get("Category")
Dim EndEpochDate As Int = Headline.Get("EndEpochDate")
Dim EffectiveEpochDate As Int = Headline.Get("EffectiveEpochDate")
Dim Severity As Int = Headline.Get("Severity")
Dim Text As String = Headline.Get("Text")
Dim EndDate As String = Headline.Get("EndDate")
Dim Link As String = Headline.Get("Link")
Dim EffectiveDate As String = Headline.Get("EffectiveDate")
Dim MobileLink As String = Headline.Get("MobileLink")
Dim DailyForecasts As List = jRoot.Get("DailyForecasts")
For Each colDailyForecasts As Map In DailyForecasts
Dim Temperature As Map = colDailyForecasts.Get("Temperature")
Dim Minimum As Map = Temperature.Get("Minimum")
Dim UnitType As Int = Minimum.Get("UnitType")
Dim Value As Double = Minimum.Get("Value")
Dim Unit As String = Minimum.Get("Unit")
Dim Maximum As Map = Temperature.Get("Maximum")
Dim UnitType As Int = Maximum.Get("UnitType")
Dim Value As Double = Maximum.Get("Value")
Dim Unit As String = Maximum.Get("Unit")
Dim Night As Map = colDailyForecasts.Get("Night")
Dim HasPrecipitation As String = Night.Get("HasPrecipitation")
Dim IconPhrase As String = Night.Get("IconPhrase")
Dim Icon As Int = Night.Get("Icon")
Dim EpochDate As Int = colDailyForecasts.Get("EpochDate")
Dim Day As Map = colDailyForecasts.Get("Day")
Dim HasPrecipitation As String = Day.Get("HasPrecipitation")
Dim IconPhrase As String = Day.Get("IconPhrase")
Dim Icon As Int = Day.Get("Icon")
Dim Sources As List = colDailyForecasts.Get("Sources")
For Each colSources As String In Sources
Next
Dim Date As String = colDailyForecasts.Get("Date")
Dim Link As String = colDailyForecasts.Get("Link")
Dim MobileLink As String = colDailyForecasts.Get("MobileLink")
Next
I am not sure how to use the above as I would like to parse the data separately and then show them on labels as Day 1, Day 2 and Day 3 etc as shown in the below image