gpt4 book ai didi

android - 通过 GSON 将 jsonString 转换为列表

转载 作者:搜寻专家 更新时间:2023-11-01 09:32:24 26 4
gpt4 key购买 nike

我已将 jsonArray 转换为字符串:

[{"Key":"Comment","Value":"گواهی پایانکار با شماره ارجاع 2168439 صادر شد","Children":""},{"Key":"Version","Value":"BIZ.SC- Version=8.8.495.1","Children":""},{"Key":"lat","Value":"0","Children":""},{"Key":"lng","Value":"0","Children":""},{"Key":"District","Value":"11","Children":""},{"Key":"ScheduledMessage","Value":"{\"Id\":\"41b02583-1974-4f31-8ba1-c58d035f388b\",\"NotificationId\":\"53a23080-88cf-4256-855c-6ef2a51f2aab\",\"DistributionId\":\"98ee1d58-dd1e-4ef9-b82a-0af2a2a0e9ef\",\"CreationDateTime\":\"\\\/Date(1504277609736)\\\/\",\"ExpirationDateTime\":\"\\\/Date(4070908800000)\\\/\",\"Address\":\"Topics\/Notifications\/Global\",\"FileName\":\"\"}","Children":""}]

现在我想通过 Gson 将其转换为 pojo java 类作为 List<EventData>

List<EventData> result = GsonUtil.createGson().fromJson(eventArray,
new TypeToken<List<EventData>>() {}.getType());

notifyParcel.setEventData(result);

这是我的 pojo 类:

public class EventData implements Serializable{
private List<Children> Children;
private String Key;
private String Value;

public List<Children> getChildren() {
return Children;
}

public void setChildren(List<Children> children) {
Children = children;
}

public String getKey() {
return Key;
}

public void setKey(String key) {
Key = key;
}

public String getValue() {
return Value;
}

public void setValue(String value) {
Value = value;
}
}

我去这个错误:

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

问题是什么?

最佳答案

在您的 JSON 示例中,Children 定义为字符串:"Children": ""。但期望 Array a.e. []

要消除此错误,您可以将 "Children": "" 替换为 "Children": [] 或尝试删除 "Children": "" 完全

关于android - 通过 GSON 将 jsonString 转换为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46004903/

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