0

I'm trying to get data from an api, but not getting the idea how. I'm working on a weather app, but weather condition is inside an array.

Look at this: enter link description here

When look at will see that the "weather" data is inside an array. all I want from this array is the "main" that inside it. So how it can be done ?

1 Answer 1

1

You can use

JsonObject jsonData=new JsonObject(responseStr);

JsonObject main=jsonData.getJsonObject("main");

String temp=main.getString("temp");
.....
JsonArray weather=jsonData.getJsonArray("weather");
for(int i=0;i<weather.lenght.i++)
 {

  JsonObject weatherChild=(JsonObject)weather.get(i);
  String id=weatherChild.getString("id") ;
  .......
 }
Sign up to request clarification or add additional context in comments.

1 Comment

yes this work with what inside the first array that in the json, but not with "weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon":"01d"}] because as you can see is an another array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.