Kotlin convert json string to list of object using Gson

后端 未结 2 1687
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 17:04

I have a problem with Kotlin to write code for conversion from JSON String to List of objects.

Normally in Java, it is like this:

  Gson gson = new Gson(         


        
2条回答
  •  既然无缘
    2021-02-20 17:25

    You could try doing this instead:

    val objectList = gson.fromJson(json, Array::class.java).asList()
    

    EDIT [14th January 2020]: You should NOT be using GSON anymore. Jake Wharton, one of the projects maintainers, suggests using Moshi, Jackson or kotlinx.serialization.

提交回复
热议问题