手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >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 Studio打包时解决V4包重复的问题

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

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

Android中使用sax解析xml文件的方法

android获取音乐文件的内置专辑图片实现思路及代码

Android从服务器端获取数据的几种方法

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

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

Android 情景模式的设置代码

Android4.2中全屏或者取消标题栏的方法总结

精品推荐
分类导航