Skip to content

Instantly share code, notes, and snippets.

@oatpano
Last active February 25, 2018 19:21
Show Gist options
  • Save oatpano/ee2710e365d68fe41fbb0d8fc1737917 to your computer and use it in GitHub Desktop.
Save oatpano/ee2710e365d68fe41fbb0d8fc1737917 to your computer and use it in GitHub Desktop.
GetJsonGenericKotlin Success
inline fun <reified T> 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