zoukankan      html  css  js  c++  java
  • 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;
        }

  • 相关阅读:
    细数ASP.NET MVC框架的7大顶级功能
    Ubuntu 10.10更新源列表
    使用iTunes将任意mp3文件转为iPhone铃声
    简单5步,在新浪微博上关联多个博客
    在windows 7 建立一个弹出光驱的快捷方式
    中国人民太伟大了!
    Ubuntu 10.10
    du 熊填数字
    WPF学习02——XAML编译
    Debugging WPF data bindings
  • 原文地址:https://www.cnblogs.com/umlzhang/p/3977831.html
Copyright © 2011-2022 走看看