Java 获取数组及其';使用GSON从JSON中删除对象

Java 获取数组及其';使用GSON从JSON中删除对象,java,gson,Java,Gson,我有这个字符串: {"cod":"200","message":0.0049,"cnt":40,"list":[{"dt":1549346400,"main":{"temp":-1.04,"temp_min":-1.04,"temp_max":-1.04,"pressure":1023.46,"sea_level":1025.98,"grnd_level":1023.46,"humidity":92,"temp_kf":0},"weather":[{"id":600,"main":"Snow",

我有这个字符串:

{"cod":"200","message":0.0049,"cnt":40,"list":[{"dt":1549346400,"main":{"temp":-1.04,"temp_min":-1.04,"temp_max":-1.04,"pressure":1023.46,"sea_level":1025.98,"grnd_level":1023.46,"humidity":92,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"небольшой снегопад","icon":"13n"}],"clouds":{"all":80},"wind":{"speed":3.26,"deg":226.502},"rain":{},"snow":{"3h":1.485},"sys":{"pod":"n"},"dt_txt":"2019-02-05 06:00:00"},{"dt":1549357200,"main":{"temp":-1.04,"temp_min":-1.04,"temp_max":-1.04,"pressure":1023.78,"sea_level":1026.44,"grnd_level":1023.78,"humidity":95,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"небольшой снегопад","icon":"13d"}],"clouds":{"all":80},"wind":{"speed":5.32,"deg":243.5},"rain":{},"snow":{"3h":1.115},"sys":{"pod":"d"},"dt_txt":"2019-02-05 09:00:00"}],"city":{"id":536203,"name":"Sankt-Peterburg","coord":{"lat":59.9167,"lon":30.25},"country":"RU"}}
这是一个JSON,我使用这些类来获取数据

public class FiveDaysWeather {

    private long dt;
    private List<WeatherTomorrow> weather = null;
    private Temp main;
    private Wind wind;

    public long getDt() {
        return dt;
    }

    public void setDt(long dt) {
        this.dt = dt;
    }

    public List<WeatherTomorrow> getWeatherTomorrow() {
        return weather;
    }

    public void setWeatherTomorrow(List<WeatherTomorrow> weather) {
        this.weather = weather;
    }

    public Temp getTemp() {
        return main;
    }

    public void setTemp(Temp main) {
        this.main = main;
    }

    public Wind getWind() {
        return wind;
    }

    public void setWind(Wind wind) {
        this.wind = wind;
    }
}

public class WeatherTomorrow {
    private String icon;
    private String description;
    private String main;
    private long id;

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMain() {
        return main;
    }

    public void setMain(String main) {
        this.main = main;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}
公开课五味天{
私人长dt;
私有列表天气=空;
私人临时总水管;
私人风;
公共长getDt(){
返回dt;
}
公共无效设置(长设置){
这1.dt=dt;
}
公众名单{
回归天气;
}
明日公众天气(列出天气){
这个天气=天气;
}
公共临时getTemp(){
回水总管;
}
公共空设置器(临时主){
this.main=main;
}
公共风{
回风;
}
公共空间风(风){
风=风;
}
}
明日公开课天气预报{
私有字符串图标;
私有字符串描述;
私有字符串主键;
私人长id;
公共字符串getIcon(){
返回图标;
}
公共无效设置图标(字符串图标){
this.icon=图标;
}
公共字符串getDescription(){
返回说明;
}
公共void集合描述(字符串描述){
this.description=描述;
}
公共字符串getMain(){
回水总管;
}
公共void setMain(字符串main){
this.main=main;
}
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
}
因此,从这个字符串中,我还需要获取有关天气的数据(温度、湿度、描述和风),这些数据位于第一个dt“1549346400”中的数组“list”中。我做了一个JSON数组,得到了“list”作为JSONArray。Yhan我从这个列表中得到了“dt 1549346400”作为JSONObject,并使用getter获取数据

现在我需要用谷歌GSON做同样的事情。阅读github上的指南,但仍然不理解如何从JSON获取0索引数据。

Gson Gson=new Gson();JsonElement元素=gson.fromJson(jsonOutput,JsonElement.class);JsonObject JsonObject=element.getAsJsonObject();JsonArray list=jsonObject.getAsJsonArray(“list”);JsonElement todaysWeather=list.get(0);JsonObject FivedaySeagher=TodaySeagher.getAsJsonObject()
String jsonStr = "{}";

Gson gson = new Gson();
JsonElement element = gson.fromJson (jsonStr, JsonElement.class);
JsonObject jsonObj = element.getAsJsonObject();