Last active
February 25, 2018 19:23
-
-
Save oatpano/f3a1b3141150da391f971c15ed303ab8 to your computer and use it in GitHub Desktop.
GetJsonGeneric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> T getMyDataModel(Context context, @RawRes int jsonFileRes) { | |
Type type = new TypeToken<T>(){}.getType(); | |
Gson gson = new Gson(); | |
InputStream inputStream = context.getResources().openRawResource(jsonFileRes); | |
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream)); | |
return gson.fromJson(bufferReader, type); | |
} | |
// วิธีเรียกใช้ | |
GenericJava.getMyDataModel<MyDataModel>(this, R.raw.json_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment