【发布时间】:2020-05-30 12:38:21
【问题描述】:
嘿,伙计们,我已经成功地从一个休息 API 获取数据并将其打印到日志中。但是,当我尝试将此响应捕获到数组列表中时,我收到一条错误消息:“无法推断参数(无法解析构造函数)。此错误显示在数组列表括号中
// Executes the network request on a background thread
try {
Response response = getWeather(locationCode, apiKey).execute();
if (cancelRequest) {
return;
}
if (response.code() == 200) {
// Weather weather = response.body().getWeather();
Log.d(TAG, "onResponse: " + response.body().toString());
List<Weather> list = new ArrayList<>(((Weather)response.body()));
//mWeather.postValue(response);
GSON 响应
{
"coord": {
"lon": -5.93,
"lat": 54.58
},
"weather": [
{
"id": 804,
"main": "Clouds",
"description": "overcast clouds",
"icon": "04d"
}
],
"base": "stations",
"main": {
"temp": 291.56,
"feels_like": 286.36,
"temp_min": 291.15,
"temp_max": 292.15,
"pressure": 1024,
"humidity": 45
},
如果有人能帮助我解决这个问题,将不胜感激。
【问题讨论】:
-
您是否添加了如下改造的 gson 转换器? addConverterFactory(GsonConverterFactory.create())
-
是的,gson 解析得很好,我可以在日志中看到它。它将它存储在数组列表中,这给我带来了麻烦
标签: java android retrofit2 android-mvvm