|
|
|
@ -22,7 +22,6 @@ val GSON: Gson by lazy { |
|
|
|
|
|
|
|
|
|
inline fun <reified T> genericType(): Type = object : TypeToken<T>() {}.type |
|
|
|
|
|
|
|
|
|
@Throws(JsonSyntaxException::class) |
|
|
|
|
inline fun <reified T> Gson.fromJsonObject(json: String?): T? {//可转成任意类型 |
|
|
|
|
return attempt { |
|
|
|
|
val result: T? = fromJson(json, genericType<T>()) |
|
|
|
@ -30,7 +29,6 @@ inline fun <reified T> Gson.fromJsonObject(json: String?): T? {//可转成任意 |
|
|
|
|
}.value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Throws(JsonSyntaxException::class) |
|
|
|
|
inline fun <reified T> Gson.fromJsonArray(json: String?): List<T>? { |
|
|
|
|
return attempt { |
|
|
|
|
val result: List<T>? = fromJson(json, ParameterizedTypeImpl(T::class.java)) |
|
|
|
|