CV_Res February 2016

Cannot Correctly Parse Json Using retrofit

I cannot figure out why my json Parsing is not working. Here is the Api I am working with. Also the link for the full json output http://api.openweathermap.org/data/2.5/forecast/daily?zip=85008&amode=json&units=metric&cnt=7&APPID=3c6fee6e3e8b5764212701d9535a36d5

{  
"city": {  
        "id": 5308655,  
        "name": "Phoenix",  
        "coord": {  
            "lon": -112.074043,  
            "lat": 33.44838  
        },  
        "country": "US",  
        "population": 0  
    },  
    "cod": "200",  
    "message": 0.014,  
    "cnt": 7,  
    "list": [  
        {  
            "dt": 1454871600,  
            "temp": {  
                "day": 10.46,  
                "min": 10.46,  
                "max": 10.46,  
                "night": 10.46,  
                "eve": 10.46,  
                "morn": 10.46  
            },  
            "pressure": 977.01,  
            "humidity": 32,  
            "weather": [  
                {  
                    "id": 800,  
                    "main": "Clear",  
                    "description": "sky is clear",  
                    "icon": "01n"  
                }  
            ],  
            "speed": 4.1,  
            "deg": 45,  
            "clouds": 0  
        },  
        {  
            "dt": 1454958000,    
            "temp": {  
                "day": 16.88,  
                "min": 3.31,  
                "max": 24.29,  
                "night": 11.29,  
                "eve": 23.78,  
                "morn": 4.31  
            },  
            "pressure": 979.15,  
            "humidity": 30,  
            "weather": [  
                {  
                    "id": 800,  
                    "main": "Clear",  
                    "description": "sky is clear",  
                    "ic        

Answers


CV_Res February 2016

Thanks to Yazan the answer is

public class Weather{
    public List<List1> list;
}


public class List1{
    double dt;
    public Temps temp;


    @Override
    public String toString() {
        return "List1{" +
                "temp min = " + temp.min + " temp max " + temp.max + " dt = "+ dt+
                '}';
    }
}


public class Temps{
    double min;
    double max;
}

}

Where Temps is not displayed by a hashmap but rather a single object. I hope this helps someone I know it helped me.


Boopathi February 2016

temp is not a an array, its class object.

One thing you should know retrofit will not support direct hash map retrieve(Pojo approach).

public HashMap<String, Temps> temp; -- This approach is wrong.

public Temps temp; -- This is correct.

If you want to store your response in HashMap, there is some other workaround, You should look that.

Post Status

Asked in February 2016
Viewed 2,286 times
Voted 8
Answered 2 times

Search




Leave an answer