Skip to content

Instantly share code, notes, and snippets.

@oatpano
Last active February 25, 2018 19:22
Show Gist options
  • Save oatpano/a3ca422f290784a143f4db04586cf719 to your computer and use it in GitHub Desktop.
Save oatpano/a3ca422f290784a143f4db04586cf719 to your computer and use it in GitHub Desktop.
GetJsonGenericKotlin
fun Context.getJsonGenericKotlin(@RawRes jsonFileRes: Int): T {
val inputStream = this.resources.openRawResource(jsonFileRes)
val bufferReader = BufferedReader(InputStreamReader(inputStream))
return gson.fromJson(bufferReader, T::class.java)
}
// วิธีเรียกใช้
getJsonGenericKotlin<MyDataModel>(R.raw.json_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment