Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android使用GSON解析JSON_Android_Json_Parsing_Gson - Fatal编程技术网

Android使用GSON解析JSON

Android使用GSON解析JSON,android,json,parsing,gson,Android,Json,Parsing,Gson,我有这个JSON结构: { "A": [ { "B": "text", "C": "text", "D": [ { "E": "text", "F": ["text","text",...] } ]

我有这个JSON结构:

{
    "A": 
    [
        {
            "B": "text",
            "C": "text",
            "D": 
            [
                {
                    "E": "text",
                    "F": ["text","text",...]
                }
            ]
        }
    ],  
    "G": 
        {
            "H": "text",
            "I": "text"
        }
}
对于这种结构,哪一个是正确的java类?我尝试了一些东西,但响应为空

这是JSON的javaBean

public class Bean {
    private Response response;


    public Response getResponse() {
        return response;
    }

    public void setResponse(Response response) {
        this.response = response;
    }


    public static class Response {
        private List<A> a;
        private G g;

        public List<A> getA() {
            return a;
        }

        public void setA(List<A> a) {
            this.a = a;
        }

        public G getG() {
            return g;
        }

        public void setG(G g) {
            this.g = g;
        }
    }

    public static class A {
        private String b;
        private String c;
        private List<D> d;

        public List<D> getD() {
            return d;
        }

        public void setD(List<D> d) {
            this.d = d;
        }

        public String getB() {
            return b;
        }

        public void setB(String b) {
            this.b = b;
        }

        public String getC() {
            return c;
        }

        public void setC(String c) {
            this.c = c;
        }
    }

    public static class D {
        String e;
        List<String> f;

        public String getE() {
            return e;
        }

        public void setE(String e) {
            this.e = e;
        }

        public List<String> getF() {
            return f;
        }

        public void setF(List<String> f) {
            this.f = f;
        }
    }

     public static class G {
        private String H;
        private String I;

        public String getH() {
            return H;
        }

        public void setH(String H) {
            this.H = H;
        }

        public String getI() {
            return I;
        }

        public void setI(String I) {
            this.I = I;
        }
    }

}
公共类Bean{
私人回应;
公共响应getResponse(){
返回响应;
}
公共无效设置响应(响应){
这个。反应=反应;
}
公共静态类响应{
私人名单a;
私人G;
公共列表getA(){
返回a;
}
公共无效setA(列表a){
这个a=a;
}
公共G getG(){
返回g;
}
公共无效设置(G){
这个.g=g;
}
}
公共静态A类{
私有字符串b;
私有字符串c;
私人名单d;
公共列表getD(){
返回d;
}
公共作废设置(列表d){
这个。d=d;
}
公共字符串getB(){
返回b;
}
公共无效立根(字符串b){
这个.b=b;
}
公共字符串getC(){
返回c;
}
公共无效setC(字符串c){
这个.c=c;
}
}
公共静态D类{
字符串e;
清单f;
公共字符串getE(){
返回e;
}
公共无效集(字符串e){
这个。e=e;
}
公共列表getF(){
返回f;
}
公共作废setF(列表f){
这个。f=f;
}
}
公共静态类别G{
私有字符串H;
私人字符串I;
公共字符串getH(){
返回H;
}
公共无效setH(字符串H){
这个,H=H;
}
公共字符串getI(){
返回I;
}
公共无效集合I(字符串I){
这个。I=I;
}
}
}

试试这一款这会有用的

ResponseBean.java

公共类响应可以实现序列化{

@SerializedName("A")
public List<A> a;

@SerializedName("G")
public G g;

 public static class A {

    @SerializedName("B")
    private String b;

    @SerializedName("C")
    private String c;

    @SerializedName("D")
    private List<D> d;
}

public static class D {

    @SerializedName("E")
    private String e;

    @SerializedName("F")
    private F f;


}

public static class G {

    @SerializedName("H")
    private String h;

    @SerializedName("I")
    private String i;


}
public static class F {

    @SerializedName("Text")
    private String h;

    @SerializedName("Text")
    private String i;


}
@SerializedName(“A”)
公开名单a;
@序列化名称(“G”)
公共G;
公共静态A类{
@序列化名称(“B”)
私有字符串b;
@序列化名称(“C”)
私有字符串c;
@序列化名称(“D”)
私人名单d;
}
公共静态D类{
@序列化名称(“E”)
私有字符串e;
@序列化名称(“F”)
私人基金;
}
公共静态类别G{
@序列化名称(“H”)
私有字符串h;
@序列化名称(“I”)
私人字符串i;
}
公共静态F类{
@序列化名称(“文本”)
私有字符串h;
@序列化名称(“文本”)
私人字符串i;
}

}

您能展示一下您的尝试吗,这样我们就可以告诉您可能存在的问题了?这看起来不像json,请看这里:@SpyZip json足够有效了。@SpyZip。。。这是有效的JSON格式,当我尝试Bean Bean=gson.formJson(jsonString,Bean.class)时,它返回响应nullnow它抛出一个异常java.lang.IllegalStateException:应该是BEGIN\u对象,但它是字符串