android - Cannot Correctly Parse Json Using retrofit -


i cannot figure out why json parsing not working. here api working with. link 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 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 clear",                       "icon": "01d"                   }               ],               "speed": 2.41,               "deg": 52,               "clouds": 0           }, 

i trying min , max temps each day. here code. exception thrown expected begin_object number @ line 1 column 190. appreciated, thank you!

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      listview listview =(listview) findviewbyid(r.id.main_activity_list);      arrayadapter = new arrayadapter<>(             this,             android.r.layout.simple_list_item_1,             android.r.id.text1,             new arraylist<list1>());      listview.setadapter(arrayadapter); }  @override protected void onresume() {     super.onresume();      httplogginginterceptor interceptor = new httplogginginterceptor();     interceptor.setlevel(httplogginginterceptor.level.body);     okhttpclient client = new okhttpclient.builder().addinterceptor(interceptor).build();      retrofit retrofit = new retrofit.builder()             .baseurl("http://api.openweathermap.org")             .client(client)             .addconverterfactory(gsonconverterfactory.create())             .build();      weatherapi weatherapi = retrofit.create(weatherapi.class);      call<weather> call = weatherapi.loadweather("85008", "json", "metric", "7", "3c6fee6e3e8b5764212701d9535a36d5");     call.enqueue(this); }  @override public void onresponse(call<weather> call, response<weather> response) {     arrayadapter.clear();     arrayadapter.addall(response.body().list); }  @override public void onfailure(call<weather> call, throwable t) {     log.v(mainactivity.class.getsimplename(), t.getlocalizedmessage()); }   public interface weatherapi {     @get("/data/2.5/forecast/daily")     call<weather> loadweather(             @query("zip")string zip,             @query("amode")string amode,             @query("units")string units,             @query("cnt")string cnt,             @query("appid")string apikey); }    public class weather{     public list<list1> list; }   public class list1{     double dt;     public hashmap<string, temps> temp;      @override     public string tostring() {         string output = "min , high ";          for(map.entry<string,temps> temps:temp.entryset()){             output += temps.getkey() + " = " + temps.getvalue().min;         }         return output;       } }   public class temps{     double min;     double max;  } 

temp not array, class object.

one thing should know retrofit not support direct hash map retrieve(pojo approach).

public hashmap<string, temps> temp; -- approach wrong.

public temps temp; -- correct.

if want store response in hashmap, there other workaround, should that.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -