gpt4 book ai didi

android - Retrofit + GSON 解析对象数组

转载 作者:行者123 更新时间:2023-11-29 20:49:34 25 4
gpt4 key购买 nike

我收到这个 jason 作为 WS 的回复:

[
[
"test0",
"test0"
],
[
"test1",
"test1"
],
[
"test2",
"test2"
],
[
"test3",
"test3"
],
[
"test4",
"test4"
],
[
"test5",
"test5"
]
]

请注意,没有名称-值字段,json 是一个字符串数组。我尝试了几次尝试来解析响应。我尝试使用带有字符串列表的 pojo,但我总是遇到同样的错误:

retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

用于改造回调的MyPOJO是下一个:

public class VotePollResults {

private List<PartialResult> fields;

public List<PartialResult> getFields() {
return fields;
}

public void setFields(List<PartialResult> fields) {
this.fields = fields;
}

public class PartialResult {

private String description;
private Integer votes;

public PartialResult(String description, Integer votes) {
this.description = description;
this.votes = votes;
}

public String getDescription() {
return description;
}

public Integer getVotes() {
return votes;
}

}

}

我有一个带有自定义对象的 List,该对象处理该 json 结构。

最佳答案

我解决了这个问题。

我必须使用它作为改造的回调

Callback<List<List<String>>>

希望这对某人有帮助...

关于android - Retrofit + GSON 解析对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29500319/

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