gpt4 book ai didi

java - 如何解析内部数组json

转载 作者:行者123 更新时间:2023-11-30 08:00:01 25 4
gpt4 key购买 nike

<分区>

我有 json:

{
"id": 1,
"result": [
{
"id": 1,
"imgUrl": "http://test.com/image.jpg",
"title": "image"
},
{
"id": 2,
"imgUrl": "http://test.com/image2.jpg",
"title": "image2"
}
],
"jsonrpc": "2.0"
}

我如何解析内部数组,我尝试使用模型默认的 retroif gson 解析

public class TestRequest {

public int id;
public List<ArrayItems> result;
public String jsonrpc;
}

public class Item {

public int id;
public String imgUrl;
public String title;
}

我有错误:应为 BEGIN_OBJECT 但实际为 BEGIN_ARRAY。然后我尝试手动解析

Item[] items = GSON.fromJson(json, Item[].class);

并有错误:

Expected BEGIN_ARRAY but was BEGIN_OBJECT.

我们要做什么?

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