Android Parsing between JSON and Kotlin Object with Google Gson Library

Parsing between JSON and Kotlin Object with Google Gson Library

dependencies {
    ...
    implementation 'com.google.code.gson:gson:2.8.6'
    ...
}
class MyClass(val name:String?=null, val address:String?=null){}
val obj = MyClass("hangj", "earth")
val strjson = Gson().toJson(obj)
val obj2 = Gson().fromJson(strjson, MyClass::class.java)

原文地址:https://www.cnblogs.com/hangj/p/13921860.html