第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

json中多個不同的嵌套對象進行改造

json中多個不同的嵌套對象進行改造

縹緲止盈 2022-03-10 16:14:51
我的 json 圖片,請點擊1 和2。 希望足夠理解。故事:我想讀一次 Json 頁面。沒關(guān)系,我對此沒有任何問題。我只能讀取第一個單元格中的數(shù)據(jù)。不同類別的其他細胞。而且我通過使用http://www.jsonschema2pojo.org/ 重要?。∶總€不同的類型,都包含不同的命名對象列表。但是如何通過改造庫將每個單元格中的數(shù)據(jù)獲取到不同的類?##精選名單##public class FeaturedList{  //this my main class@SerializedName("featured")private List<FeaturedItem> featured;@SerializedName("type")private String type;@SerializedName("title")private String title;public void setFeatured(List<FeaturedItem> featured){    this.featured = featured;}public List<FeaturedItem> getFeatured(){    return featured;}public void setType(String type){    this.type = type;}public String getType(){    return type;}public void setTitle(String title){    this.title = title;}public String getTitle(){    return title;}@Overridepublic String toString(){    return         "FeaturedList{" +         "featured = '" + featured + '\'' +         ",type = '" + type + '\'' +         ",title = '" + title + '\'' +         "}";    }主要活動     restInsterface = ApiClient.getClient().create(RestInsterface.class);    Call<List<FeaturedList>> listCall;    listCall=restInsterface.getFeaturedList();    listCall.enqueue(new Callback<List<FeaturedList>>() {        @Override        public void onResponse(Call<List<FeaturedList>> call, Response<List<FeaturedList>> response) {            for (FeaturedList item:response.body()){                Log.i(TAG, "onResponse: "+item.toString());            }        }        @Override        public void onFailure(Call<List<FeaturedList>> call, Throwable t) {        }    });      }
查看完整描述

2 回答

?
森林海

TA貢獻2011條經(jīng)驗 獲得超2個贊

好吧,我做到了,這是我的解決方案。它有效。


 public class DataList{


@SerializedName("featured")

private List<FeaturedItem> featured;

@SerializedName("products")

private List<ProductsItem> products;

@SerializedName("categories")

private List<CategoriesItem> categories;

@SerializedName("collections")

private List<CollectionsItem> collections;

@SerializedName("shops")

private List<ShopsItem> shops;


@SerializedName("type")

private String type;


@SerializedName("title")

private String title;


public List<FeaturedItem> getFeatured() {

    return featured;

}


public void setFeatured(List<FeaturedItem> featured) {

    this.featured = featured;

}


public List<ProductsItem> getProducts() {

    return products;

}


public void setProducts(List<ProductsItem> products) {

    this.products = products;

}


public List<CategoriesItem> getCategories() {

    return categories;

}


public void setCategories(List<CategoriesItem> categories) {

    this.categories = categories;

}


public List<CollectionsItem> getCollections() {

    return collections;

}


public void setCollections(List<CollectionsItem> collections) {

    this.collections = collections;

}


public List<ShopsItem> getShops() {

    return shops;

}


public void setShops(List<ShopsItem> shops) {

    this.shops = shops;

}


public void setType(String type){

    this.type = type;

}


public String getType(){

    return type;

}


public void setTitle(String title){

    this.title = title;

}


public String getTitle(){

    return title;

}


@Override

public String toString(){

    if(type.equals("featured")){

        return

                "Featured Olanlar{" +

                        "featured = '" + featured + '\'' +

                        ",type = '" + type + '\'' +

                        ",title = '" + title + '\'' +

                        "}";

    }

    else if(type.equals("new_products")){

        return

                "En Yeni ürünler{" +

                        "products = '" + products + '\'' +

                        ",type = '" + type + '\'' +

                        ",title = '" + title + '\'' +

                        "}";

    }

    else if(type.equals("categories")){

        return

                "Kategoriler{" +

                        "categories = '" + categories + '\'' +

                        ",type = '" + type + '\'' +

                        ",title = '" + title + '\'' +

                        "}";

    }

    else if(type.equals("collections")){

        return

                "Koleksiyonlar{" +

                        "collections = '" + collections + '\'' +

                        ",type = '" + type + '\'' +

                        ",title = '" + title + '\'' +

                        "}";

    }

    else if(type.equals("editor_shops")){

        return

                "Edit?r Se?imi Vitrinler{" +

                        "shops = '" + shops + '\'' +

                        ",type = '" + type + '\'' +

                        ",title = '" + title + '\'' +

                        "}";

    }

    else if(type.equals("new_shops")){

        return

                "En Yeni Vitrinler{" +

                        "shops = '" + shops + '\'' +

                        ",type = '" + type + '\'' +

                        ",title = '" + title + '\'' +

                        "}";

    }

    return null;

    }  

        }



查看完整回答
反對 回復 2022-03-10
?
慕神8447489

TA貢獻1780條經(jīng)驗 獲得超1個贊

可以解析同一級別的對象的不同命名。在一種方式中,可以定義@SerializedName(value="name1", alternate={"name2", "name3"}) String b;含義,定義對象的替代名稱。但要小心這個對象需要有相同的數(shù)據(jù)。在您的情況下,它將在所有情況下解析"id","name",因為 json 在所有情況下都包含這兩個字段。

另一方面,當您想要解析所有字段時,最好使用自定義JsonDeserializer。您可以在此處找到如何為 GSON 庫編寫自己的反序列化器的示例:反序列化器


查看完整回答
反對 回復 2022-03-10
  • 2 回答
  • 0 關(guān)注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號