Android 通过GSON将jsonString转换为list
我已将jsonArray转换为字符串:Android 通过GSON将jsonString转换为list,android,arraylist,gson,Android,Arraylist,Gson,我已将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","Childre
[{"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将其转换为pojojava类,作为列表
问题出在哪里?在您的JSON示例中,定义为字符串的
子项:
“子项”:“。但需要阵列a.e.[]
要消除此错误,您可以将
“Children”:“
替换为“Children”:[]
,或尝试删除“Children”:“我更改为它:。但是我得到了这个错误:应该是BEGIN\u数组,但在第1行第87列路径$[0]处是字符串。Children
@sayres抱歉,mate,输入错误:应该是[]
a.e.`“Children”:[]`:dude这是我保存这个Children的地方。我到底能做什么?我不能将[]放在没有“@sayres”的地方,而是添加“[]”,添加new JSONArray()
List<EventData> result = GsonUtil.createGson().fromJson(eventArray,
new TypeToken<List<EventData>>() {}.getType());
notifyParcel.setEventData(result);
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 $