JSON Weather Parser
Once we have created our model we have to parse it. We can create a specific class that handles this task. First we have to create the “root” object that receive as input the entire string containing all the JSON response:
Then we start parsing each piece of the response:
In the line 4,8 we create two “sub” object (coordObj and sysObj) having as parent the jObj as it clear from the JSON response. As we can see we use some helper methods to get String,int and float values:
And then we finally parse the weather information. We have to remember that weather tag is an array so we have to handle it differently
At the end we have our Weather class filled with the data retrieved.