欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android讀取本地json文件的方法(解決顯示亂碼問題)

 更新時間:2016年06月30日 15:32:10   作者:居后不爭  
這篇文章主要介紹了Android讀取本地json文件的方法,結(jié)合實例形式對比分析了解決顯示亂碼問題的方法,需要的朋友可以參考下

本文實例講述了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文件設(shè)置時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;
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論