国产视频最新网址|这里只有精品中文字幕情侣酒店|精品成人一区二区|91久久蜜桃网站|AV成人电影五区|欧美精品在线一区|秋霞午夜一区日韩|国产午夜成人免费看片不卡|98精品美女视频日韩一区精品视频|亚洲综合久久国产不卡日本岛国久久

Android讀取本地json文件的方法

時(shí)間:2024-07-06 22:46:52 JSON 我要投稿
  • 相關(guān)推薦

Android讀取本地json文件的方法

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

【Android讀取本地json文件的方法】相關(guān)文章:

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

excel合并多個(gè)文件的方法05-27

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

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

Node.js如何響應(yīng)Ajax的POST請(qǐng)求并且保存為JSON文件詳解03-29

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

word 恢復(fù)未保存文件的方法01-04

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

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