我面對這個錯誤在解析JSON數據Android的JSON錯誤com.google.gson.JsonSyntaxException:java.lang.IllegalStateException
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2
我could'nt找到解決方案。我的JSON數據是:
{
"user": [
{
"email": "[email protected]",
"firstName": "Wijden",
"id": "1",
"lastName": "User"
}, {
"email": "[email protected]",
"firstName": "Sample",
"id": "2",
"lastName": "User"
}, {
"email": "[email protected]",
"firstName": "Ingenieur",
"id": "3",
"lastName": "User"
}
]
}
而且我這是怎麼做的:
Type type = new TypeToken<List<WorkItem>>() { }.getType();
List<WorkItem> workitems = (List<WorkItem>) new Gson().fromJson(resultat, type);
我將不勝感激,如果你能幫助我解決tnis問題。在此先感謝
JSONLint是你的朋友:http://jsonlint.com/。在這種情況下,您剪切/粘貼的三條線是有效的。所以問題是「別的東西」。問:你能提供更多的代碼嗎?問:你能否把事情分解成幾個額外的子變量,而不是一次性用「new Gson()。fromJson()」做所有事情? – paulsm4