Android讀取本地json文件的方法

時間:2024-07-06 22:46:52 JSON 我要投稿
  • 相關推薦

Android讀取本地json文件的方法

  本文實例講述了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讀取本地json文件的方法】相關文章:

隱藏電腦文件的方法03-19

excel合并多個文件的方法05-27

壓縮視頻文件的方法03-20

配置本地路由的常見方法介紹03-03

Node.js如何響應Ajax的POST請求并且保存為JSON文件詳解03-29

iphone和電腦傳文件的方法03-21

word 恢復未保存文件的方法01-04

mac給文件夾加密的方法03-12

解決本地連接故障的三個方法03-06

亚洲制服丝袜二区欧美精品,亚洲精品无码视频乱码,日韩av无码一区二区,国产人妖视频一区二区
亚洲丁香七月色婷婷 | 亚洲精品国产精品制服丝袜 | 在线综合亚洲欧美首页 | 亚洲欧美日韩v在线观看不卡 | 日本中文字幕在线看 | 亚洲欧美日本大码在线 |