Android读取本地json文件的方法

时间:2023-03-29 15:36:22 JSON 我要投稿
  • 相关推荐

Android读取本地json文件的方法

  本文实例讲述了Android读取本地json文件的方法。分享给大家供大家参考,具体如下:

  1、读取本地JSON ,但是显示汉字乱码

  public static String readLocalJson(Context context, String fileName){ String jsonString=""; String resultString=""; try { BufferedReader bufferedReader=new BufferedReader(new InputStreamReader( context.getResources().getAssets().open(fileName))); while ((jsonString=bufferedReader.readLine())!=null) { resultString+=jsonString; } } catch (Exception e) { // TODO: handle exception } return resultString;}

  2、读取本地JSON,显示汉字正确,txt文件设置时UTF-8,UNIX

  public static String readLocalJson(Context context, String fileName){ String jsonString=""; String resultString=""; try { InputStream inputStream=context.getResources().getAssets().open(fileName); byte[] buffer=new byte[inputStream.available()]; inputStream.read(buffer); resultString=new String(buffer,"utf-8"); } catch (Exception e) { // TODO: handle exception } return resultString;}

【Android读取本地json文件的方法】相关文章:

解决本地连接故障的三个方法08-24

添加网络位置文件夹的方法02-16

Ajax使用JSON数据格式案例分析06-02

excel文件出现乱码的原因及解决方法07-18

了解西安本地的小升初流程08-12

电脑里哪些文件属于垃圾文件05-30

监理文件资料的类型-监理文件资料分类09-24

ai文件怎么导出保存为ps文件04-27

ISO文件怎么安装06-05

Log是什么文件06-07