/**
* Get the json data from json file.
*
* @param context the context to acces the resources.
* @param fileName the name of the json file
* @return json as string
*/
public static String getJsonFromAsset(Context context, String fileName) {
String json = "";
try {
InputStream stream = context.getAssets().open(fileName);
int size = stream.available();
byte[] buffer = new byte[size];
stream.read(buffer);
stream.close();
json = new String(buffer, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
Я уже закончил работу с Java, но с Kotlin мне сложно.
Я уже искал в Google, но ни один из них мне не помог.
[code]/** * Get the json data from json file. * * @param context the context to acces the resources. * @param fileName the name of the json file * @return json as string */ public static String getJsonFromAsset(Context context, String fileName) { String json = ""; try { InputStream stream = context.getAssets().open(fileName); int size = stream.available(); byte[] buffer = new byte[size]; stream.read(buffer); stream.close(); json = new String(buffer, "UTF-8");