查看这篇文章Reading a json file in Android。我用什么替换下面的行 -
json_return_by_the_function
我需要将函数返回值保存在字符串中。
public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getAssets().open("file_name.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
JSONObject obj = new JSONObject(json_return_by_the_function);