如何在gson对象模型类android中获取多少键?

问题描述

我收到的回复如下:

    "field_1":{
        
    },"field_2" : {
        "array_2": [
            {
                ... all other fields
            }
        ],"array_1": [
            {
               ... all other fields
            }
        ],// here will have 4 array or 5 array,I want to get how many array is inside this object
    },"field_3":{

    }

所以我让我的POJO类看起来像这样:

public class MyPojo{

    @SerializedName("field_1")
    @Expose
    private Field1 class1;


    @SerializedName("field_2")
    @Expose
    private Field2 class2;

    @SerializedName("field_3")
    @Expose
    private Field3 class3;

    // other getter and setter 
}

然后我将有一个Field2类,如下所示:

public class Entities {

    @SerializedName("array_1")
    @Expose
    private List<Array1Item> arraylist1 = null;
    @SerializedName("array_2")
    @Expose
    private List<Array2Item> arraylist2 = null;

    @SerializedName("array_3")
    @Expose
    private List<Array3Item> arraylist3 = null;

   //other getter setter

}

现在的问题是我想知道field_2对象中有多少个数组。看来我无法访问field_2对象。

我尝试通过field2.names()访问它,但无法解析。

因此请有人帮忙。

我想要的是array 1中存在多少个array 2field_2之类的密钥?它将返回int中的值。我该怎么办?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)