我有一個從服務器輸出的字符串,我試圖從字符串中提取一些值。將字符串轉換爲gson對象
下面是來自服務器的輸出:
jsonString =
{
"MEANING":"reduce",
"DISPLAY":"",
"TYPE_CD":1,
"SELECTED_IND":1,
"CNT":1,
"SOURCES":[
{ "a":1 }
]
}
代碼:
JsonReader reader = new JsonReader(new StringReader(jsonString));
DataObject obj1 = new Gson().fromJson(reader, DataObject.class);
數據對象類:
DataObject
{
private int MEANING;
private int CNT;
private String TYPE_CD;
private String DISPLAY;
private String MEANING;
private List<Long> SOURCES;
public String getSourceTypeMeaning()
{
return this.MEANING;
}
public String getSourceTypeDisplay()
{
return this.DISPLAY;
}
public String getSourceTypeCd()
{
return this.TYPE_CD;
}
public int getSourceCount()
{
return this.CNT;
}
public List<Long> getSourceList()
{
return this.SOURCES;
}
}
,但得到這個錯誤
Expected a string but was BEGIN_OBJECT at line 1 column 132
我無法用我的代碼找到問題。
請問,可否downvoter解釋downvote的原因? – MikO
+1 @Miko糾正每個人,是的來源是一個列表。 –