荟萃馆

位置:首页 > 设计 > 网页设计

Android读取本地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( esources()ssets()(fileName))); while ((jsonString=Line())!=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=esources()ssets()(fileName); byte[] buffer=new byte[lable()]; (buffer); resultString=new String(buffer,"GB2312"); } catch (Exception e) { // TODO: handle exception } return resultString;}