簡體   English   中英

我無法在使用 android 中使用 java 的改造 2 中收到呼叫響應無法解析 model

[英]I cannot receive response in call using retrofit2 using java in android cannot parse response in model

這是一個單元素數組。 我無法在 android 中使用 java 使用改造 2 在通話中收到它 我正在使用這個 model

    @SerializedName("timelineitems")
    public List<HashMap<String,Data>> data;

    public class Data{

            @SerializedName("new_daily_cases")
            public String new_cases;

    }

但在最后一行找到 object 字符串

            "stat": "ok"

這一行使調用運行失敗

"timelineitems":[
{
    "4/17/20": {
                "new_daily_cases": 150,
                "new_daily_deaths": 16,
                "total_cases": 2418,
                "total_recoveries": 65,
                "total_deaths": 364
            },
            "4/18/20": {
                "new_daily_cases": 116,
                "new_daily_deaths": 3,
                "total_cases": 2534,
                "total_recoveries": 65,
                "total_deaths": 367
            },
            "stat": "ok"
        }
    ]

那是我用來解決問題的 model 公共 class 模型{

@SerializedName("timelineitems")
public List<HashMap<String,Object>> data;

public class Data{

    @SerializedName("new_daily_cases")
    public String new_cases;
    @SerializedName("new_daily_deaths")
    public String new_daily_deaths;
    @SerializedName("total_cases")
    public String total_cases;
    @SerializedName("total_recoveries")
    public String total_recoveries;
    @SerializedName("total_deaths")
    public String total_deaths;

}

}

然后我用這段代碼來獲取我的數據

嘗試{ Model 資源=response.body();

                   HashMap<String,Object>data=resource.data.get(0);

                    Gson g = new Gson();
                    Data inf = g.fromJson(g.toJson(resource.data.get(0).get(date0)), Data.class);



                }catch (NullPointerException e){
                   =
                    Toast.makeText(getApplicationContext(),"No data available",Toast.LENGTH_LONG).show();
                }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM