//根据读取到的string创建json对象
private static JSONObject getJsonObject(String fileName) {
JSONObject object = null;
String jsonStr = getJsonStr(fileName);
if (jsonStr != null) {
try {
object = new JSONObject(jsonStr);
} catch (JSONException e) {
e.printStackTrace();
}
}
return object;
}
//从文件读取jsonstr
private static String getJsonStr(String fileName) {
StringBuilder stringBuilder = new StringBuilder();
try {
BufferedReader bf = new BufferedReader(new InputStreamReader(VPVoicePlus.application.getAssets().open(fileName)));
String line;
while ((line = bf.readLine()) != null) {
stringBuilder.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
从.json文件中初始化得到JsonObject对象
最新推荐文章于 2024-08-13 08:49:36 发布