Skip to content

Instantly share code, notes, and snippets.

@oatpano
Last active February 26, 2018 16:06
Show Gist options
  • Save oatpano/8acb71b7c334dab427da171dd469f065 to your computer and use it in GitHub Desktop.
Save oatpano/8acb71b7c334dab427da171dd469f065 to your computer and use it in GitHub Desktop.
GetJsonClassParameter
public static T getJsonClassParameter(Context context, @RawRes int jsonFileRes, Class<T> classType) {
Gson gson = new Gson();
InputStream inputStream = context.getResources().openRawResource(jsonFileRes);
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream));
return gson.fromJson(bufferReader, classType);
}
// วิธีเรียกใช้
GenericJava.getJsonClassParameter(this, R.raw.json_text, MyDataModel.class)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment