手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android读取本地json文件的方法(解决显示乱码问题)
Android读取本地json文件的方法(解决显示乱码问题)
摘要:本文实例讲述了Android读取本地json文件的方法。分享给大家供大家参考,具体如下:1、读取本地JSON,但是显示汉字乱码publics...

本文实例讲述了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程序设计有所帮助。

【Android读取本地json文件的方法(解决显示乱码问题)】相关文章:

Android 原始资源文件的使用详解

Android中使用pull解析器操作xml文件的解决办法

解决android 下载时文件名中文和空格问题

基于将Android工程做成jar包和资源文件的解决方法

Android 读写文件方法汇总

解决Android SDK下载和更新失败的方法详解

用Android Location获取当前地理位置的方法

Android 情景模式的设置代码

Android 图片特效处理的方法实例

Android编程设置全屏的方法实例

精品推荐
分类导航