从.json文件中初始化得到JsonObject对象

来源:互联网 发布:洪珮云 知乎 编辑:程序博客网 时间:2024/06/06 03:11
//根据读取到的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();    }
0 0
原创粉丝点击