Android Question Parsing Json Array

khwarizmi

Active Member
Licensed User
Longtime User
Hi all
How to parse this Json array:

{"coord":{"lon":32,"lat":15},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"base":"stations","main":{"temp":22.08,"feels_like":20.79,"temp_min":22.08,"temp_max":22.08,"pressure":1013,"humidity":17,"sea_level":1013,"grnd_level":963},"visibility":10000,"wind":{"speed":4.96,"deg":344,"gust":6.23},"clouds":{"all":66},"dt":1737822990,"sys":{"country":"SD","sunrise":1737778898,"sunset":1737820003},"timezone":7200,"id":379014,"name":"Al Qiţena","cod":200}

Thanks.
 
Solution
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim visibility As Int = jRoot.Get("visibility")
Dim timezone As Int = jRoot.Get("timezone")
Dim main As Map = jRoot.Get("main")
Dim temp As Double = main.Get("temp")
Dim temp_min As Double = main.Get("temp_min")
Dim grnd_level As Int = main.Get("grnd_level")
Dim humidity As Int = main.Get("humidity")
Dim pressure As Int = main.Get("pressure")
Dim sea_level As Int = main.Get("sea_level")
Dim feels_like As Double = main.Get("feels_like")
Dim temp_max As Double = main.Get("temp_max")
Dim clouds As Map = jRoot.Get("clouds")
Dim all As Int = clouds.Get("all")
Dim sys As Map = jRoot.Get("sys")
Dim country As String = sys.Get("country")
Dim sunrise As...

Pendrush

Well-Known Member
Licensed User
Longtime User
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim visibility As Int = jRoot.Get("visibility")
Dim timezone As Int = jRoot.Get("timezone")
Dim main As Map = jRoot.Get("main")
Dim temp As Double = main.Get("temp")
Dim temp_min As Double = main.Get("temp_min")
Dim grnd_level As Int = main.Get("grnd_level")
Dim humidity As Int = main.Get("humidity")
Dim pressure As Int = main.Get("pressure")
Dim sea_level As Int = main.Get("sea_level")
Dim feels_like As Double = main.Get("feels_like")
Dim temp_max As Double = main.Get("temp_max")
Dim clouds As Map = jRoot.Get("clouds")
Dim all As Int = clouds.Get("all")
Dim sys As Map = jRoot.Get("sys")
Dim country As String = sys.Get("country")
Dim sunrise As Int = sys.Get("sunrise")
Dim sunset As Int = sys.Get("sunset")
Dim dt As Int = jRoot.Get("dt")
Dim coord As Map = jRoot.Get("coord")
Dim lon As Int = coord.Get("lon")
Dim lat As Int = coord.Get("lat")
Dim weather As List = jRoot.Get("weather")
For Each colweather As Map In weather
 Dim icon As String = colweather.Get("icon")
 Dim description As String = colweather.Get("description")
 Dim main As String = colweather.Get("main")
 Dim id As Int = colweather.Get("id")
Next
Dim name As String = jRoot.Get("name")
Dim cod As Int = jRoot.Get("cod")
Dim id As Int = jRoot.Get("id")
Dim base As String = jRoot.Get("base")
Dim wind As Map = jRoot.Get("wind")
Dim deg As Int = wind.Get("deg")
Dim speed As Double = wind.Get("speed")
Dim gust As Double = wind.Get("gust")

Paste your JSON here:
 
Upvote 2
Solution

khwarizmi

Active Member
Licensed User
Longtime User
Thank you Pendrush, there is just a confusion in the phrase:
B4X:
Dim main As String
but I changed the variable name so that it does not conflict with the model name.
 
Upvote 0

Similar Threads

Top