手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >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文件的方法(解决显示乱码问题)】相关文章:

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

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

Android界面刷新的方法分享

Android手机内存中文件的读写方法小结

Android 进入设备后台data文件夹的办法

Android Studio打包时解决V4包重复的问题

Android 4.1源码编译找不到资源文件解决办法

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

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

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

精品推荐
分类导航