从.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(); }
相关文章推荐
- java object默认的基本方法
- Objective-C 知识要点(术语表)
- OBjective-C NSString常用方法
- 点击 tableViewCell 里的 button 时如何确定是哪一个 cell
- 对const object(const对象)的理解
- Objective-C枚举类型详解
- Programming with Objective-C(一)
- Xcode(object-c) 常用代码段
- 协议(protocol)
- 我对XCode Objective-c Cocoa的简单理解
- objective-c 的方法(method)
- 浅谈ObjectAnimator设置动画
- java泛型的使用(二)在实例化对象时不指定泛型,则自动识别为object
- JavaAPI之java.lang.Object
- 10个Objective-C基础面试题
- [arr firstObject] 和 arr[0] 的区别
- NSObject的hash方法
- 问题处理之detectMultiScale函数objects返回值异常
- Node.js学习 - Global Object
- iOS中通知中心的概念知识吧(objective - c版)