android应用将json数据打包在本地,进行读取的代码
可将json文件放在assets文件夹下面,用如下方法读取
/** * add by linsen * * @return the callback json string */ public void getJSONData() { // json读取 new Thread(){ public void run(){ InputStream fis = null; BufferedReader br = null; try { fis = getAssets().open("allbrand.json"); } catch (IOException e) { e.printStackTrace(); Log.d("0618", "==========" + fis); } Scanner scanner = new Scanner(fis); while(scanner.hasNext()){ strB.append(scanner.next()); } scanner.close(); try { fis.close(); } catch (IOException e) { e.printStackTrace(); } mHandler.sendEmptyMessage(0x1234); Log.v("0618","msg sended"); } }.start(); }
由于文件读取时间较长,帮开启了线程.
自定义的读取时的dialog在线程期间启动.