您的位置:首页 > 移动开发 > Objective-C

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

2016-04-16 21:20 495 查看
//根据读取到的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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: