I am not able to convert a JSON Array into a GroupModel
array. Below is the JSON I used:
[{
"description":"My expense to others",
"items":["aaa","bbb"],
"name":"My Expense"
},
{
"description":"My expense to others","
items":["aaa","bbb"],
"name":"My Expense"
}]
and the GroupModel
class is:
class GroupModel {
var name: String? = null
var description: String? = null
var items: MutableList<String>? = null
constructor(name: String, description: String, items: MutableList<String>) {
this.name = name
this.description = description
this.items = items
}
}
and trying the following code results in an Exception
:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
The code:
var model = gson.fromJson<Array<GroupModel>>(inputString, GroupModel::class.java)