How do I convert a JSONObject to class object?

后端 未结 5 1231
南旧
南旧 2020-12-05 18:19

I need to convert a JSONObject to a Location object using gson libraries for an android project of mine. I\'m not sure on how to do this. Can anyone help me with this. Thank

5条回答
  •  没有蜡笔的小新
    2020-12-05 19:01

    For kotlin

     val objType = object : TypeToken() {
    
        }.getType()
        var myclassObj = gson.fromJson(value,objType) 
    

    or

     val objectResponse = Gson().fromJson(Gson().toJson(resp), MyClass::class.java)
    

提交回复
热议问题