gpt4 book ai didi

java - GSON 堆栈溢出错误

转载 作者:行者123 更新时间:2023-11-29 09:31:56 25 4
gpt4 key购买 nike

我正在尝试使用 Gson 从 Json 字符串中获取 filters 数组,但我一直收到此错误,有人知道我该如何解决这个问题吗?

这是 logCat 输出:

 Process: com.betterbilljsonparser, PID: 20491
java.lang.StackOverflowError
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381)
at ...
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:141)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
at com.google.gson.Gson.getAdapter(Gson.java:359)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:122)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:46)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:92)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:91)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
at com.google.gson.Gson.getAdapter(Gson.java:359)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:122)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:46)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:92)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:91)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:142)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:83)
at com.google.gson.Gson.getAdapter(Gson.java:359)

这是我的 JSON 字符串:

{
"value": 1,
"value": 2,

"other_object":{
"someval":"lorem",
"other_val":false
},

"filters": [
        {
            "items": [
                {
                    "default": true,
                    "order": 0,
                    "val": [
                        0
                    ],
                    "name": "Nope"
                },
                {
                    "default": false,
                    "name": "iPhone 5c",
                    "val": [
                        148
                    ],
                    "order": 1
                },
                {
                    "default": false,
                    "name": "iPhone 5s",
                    "val": [
                        149
                    ],
                    "order": 2
                },
                {
                    "default": false,
                    "name": "iPhone 6",
                    "val": [
                        147
                    ],
                    "order": 3
                },
                {
                    "default": false,
                    "name": "iPhone 6 Plus",
                    "val": [
                        146
                    ],
                    "order": 4
                },
                {
                    "default": false,
                    "name": "Galaxy S5",
                    "val": [
                        150
                    ],
                    "order": 5
                },
                {
                    "default": false,
                    "name": "Galaxy S6",
                    "val": [
                        154
                    ],
                    "order": 6
                },
                {
                    "default": false,
                    "name": "HTC One M9",
                    "val": [
                        155
                    ],
                    "order": 7
                },
                {
                    "default": false,
                    "name": "Sony Xperia Z3",
                    "val": [
                        152
                    ],
                    "order": 8
                }
            ],
            "type": "long",
            "key": "handset.model",
            "title": "Want a new phone with your contract?"
        },
        {
            "items": [
                {
                    "default": true,
                    "name": "3G",
                    "val": [],
                    "order": 0
                },
                {
                    "default": false,
                    "name": "4G",
                    "val": [
                        "4G"
                    ],
                    "order": 1
                }
            ],
            "type": "str",
            "key": "network_generation_name",
            "title": "3G or 4G? (4G is faster)"
        }
]
}

这是我的代码:

Gson gson = new Gson();
Response data = gson.fromJson(jsonString, Response.class);

Response.class

public class Response extends BaseMo {

@Expose
private List<Filter> filters = new ArrayList<Filter>();

/**
* @return The filters
*/
public List<Filter> getFilters() {
return filters;
}

/**
* @param filters The filters
*/
public void setFilters(List<Filter> filters) {
this.filters = filters;
}
}

Fiter.class

public class Filter extends BaseMo {

@Expose
private List<Item> items = new ArrayList<Item>();
@Expose
private String type;
@Expose
private String key;
@Expose
private String title;

/**
*
* @return
* The items
*/
public List<Item> getItems() {
return items;
}

/**
*
* @param items
* The items
*/
public void setItems(List<Item> items) {
this.items = items;
}

/**
*
* @return
* The type
*/
public String getType() {
return type;
}

/**
*
* @param type
* The type
*/
public void setType(String type) {
this.type = type;
}

/**
*
* @return
* The key
*/
public String getKey() {
return key;
}

/**
*
* @param key
* The key
*/
public void setKey(String key) {
this.key = key;
}

/**
*
* @return
* The title
*/
public String getTitle() {
return title;
}

/**
*
* @param title
* The title
*/
public void setTitle(String title) {
this.title = title;
}

}

Item.class

public class Item extends BaseMo {

@SerializedName("default")
@Expose
private boolean _default;
@Expose
private String name;
@Expose
private List<String> val = new ArrayList<String>();
@Expose
private long order;
public Item() {

}


public Item(boolean _default, String name, List<String> val, long order) {
this._default = _default;
this.name = name;
this.val = val;
this.order = order;
}

/**
* @return The _default
*/
public boolean isDefault() {
return _default;
}

/**
* @param _default The default
*/
public void setDefault(boolean _default) {
this._default = _default;
}

/**
* @return The name
*/
public String getName() {
return name;
}

/**
* @param name The name
*/
public void setName(String name) {
this.name = name;
}

/**
* @return The val
*/
public List<String> getVal() {
return val;
}

/**
* @param val The val
*/
public void setVal(List<String> val) {
this.val = val;
}

/**
* @return The order
*/
public long getOrder() {
return order;
}

/**
* @param order The order
*/
public void setOrder(long order) {
this.order = order;
}

}

最佳答案

您的 json 的第 8 行缺少昏迷。你可以在这里检查你的 json: http://www.jsoneditoronline.org/

关于java - GSON 堆栈溢出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31607502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com