Android读取本地json文件的方法

时间:2020-11-09 15:51:28 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,"GB2312"); } catch (Exception e) { // TODO: handle exception } return resultString;}

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

1.Java读取xml文件的方法

2.PHP中读取大文件实现方法

3.package.json文件的配置教程

4.Android XML文件中的@、?、@+的意义

5.json实例解析方法

6.Java如何读取文件内容再编辑

7.拒绝木马读取硬盘的方法

8.IOS中Json解析实例方法详解