gpt4 book ai didi

android - 尝试在 Android 中解析 Json,获取 arraylist 异常

转载 作者:太空狗 更新时间:2023-10-29 14:25:48 26 4
gpt4 key购买 nike

我有一个这样的 json:

[{"campaignName":"2012 Q1","id":1,"source":"Added by subject","status":"Draft","subject":"Test Subject1"},{"campaignName":"2012 Q2","id":2,"source":"Added by reviewer","status":"Created","subject":"Test Subject2"},{"campaignName":"2012 Q2","id":3,"source":"Added by reviewer","status":"Created","subject":"Test Subject62"}]

我有课:

public class Json_ToDoData {
private ArrayList<ToDo> mList;

public Json_ToDoData() {

}

public ArrayList<ToDo> getmList() {
return mList;
}

public void setmList(ArrayList<ToDo> mList) {
this.mList = mList;
}

和:`public class ToDo { 公共(public)待办事项(){

@SerializedName("campaignName")
private String campaignName;

@SerializedName("id")
private String id;

@SerializedName("source")
private String source;

@SerializedName("status")
private String status;

@SerializedName("subject")
private String subject; ... gettes and settes ...}`

我总是得到一个异常(exception):

10-08 15:17:46.600: W/System.err(2557): java.lang.ClassCastException: java.util.ArrayList and I do not understand why. here is my line to parse:

            Json_ToDoData rr = new JSONDeserializer<Json_ToDoData>().deserialize(sb.toString(), Json_ToDoData.class);

请帮帮我,谢谢

最佳答案

我认为问题是用户 json 字符串的格式不正确。尝试将您的 json 字符串格式化为以下格式:

{ 
jsonObjectName:
[
{
"campaignName":"2012 Q1",
"id":1,
"source":"Added by subject",
"status":"Draft",
"subject":"Test Subject1"
}
]
}

关于android - 尝试在 Android 中解析 Json,获取 arraylist 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12784658/

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