Kotlin convert json array to model list using GSON

后端 未结 3 799
一个人的身影
一个人的身影 2021-02-13 05:15

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\"         


        
3条回答
  •  半阙折子戏
    2021-02-13 05:33

    [{
      "description":"My expense to others",
      "items":["aaa","bbb"],
      "name":"My Expense"
     },
     {
      "description":"My expense to others","
      items":["aaa","bbb"],
      "name":"My Expense"
     }]
    

    Kotlin Code

    val gson = GsonBuilder().create()
    val Model= gson.fromJson(body,Array::class.java).toList()
    

    Gradle

    implementation 'com.google.code.gson:gson:2.8.5'
    

提交回复
热议问题