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;
        }

  • 相关阅读:
    JAVA 继承
    JAVA 封装
    windows下vi/vim编辑器的基本操作
    Emacs 快速指南
    如何批量下载bing的背景图片?
    C#制作ActiveX插件
    MQTT协议
    三年前做的代码生成器,可以做为新手学习之用,当时忘了放上源码,实在抱歉!
    nginx lua 打印 特定 header
    利用Php ssh2扩展实现svn自动提交到测试服务器
  • 原文地址:https://www.cnblogs.com/umlzhang/p/3977831.html
Copyright © 2011-2022 走看看