編輯:關於Android編程
本文實例講述了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相關內容感興趣的讀者可查看本站專題:《Android操作json格式數據技巧總結》、《Android數據庫操作技巧總結》、《Android編程之activity操作技巧總結》、《Android文件操作技巧匯總》、《Android編程開發之SD卡操作方法匯總》、《Android開發入門與進階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
Android編程之絕對布局AbsoluteLayout和相對布局RelativeLayout實例詳解
本文實例分析了Android編程之絕對布局AbsoluteLayout和相對布局RelativeLayout。分享給大家供大家參考,具體如下: 一、絕對布局Ab
Android UI基礎——五大布局
一個豐富的界面是由很多個控件組成的,如何讓各個控件都有條不紊的擺放在介面上,這就需要布局來實現了,布局可以說是一種容器,可以按照一定規律調整控件的位置,布局之內也可以放置
Android中通過ViewHelper.setTranslationY實現View移動控制(NineOldAndroids開源項目)
我們知道有不少開源工程,能實現很多不錯的效果。前幾天,我看了一個效果,剛好項目中也用到了這個jar包。沒事挖一挖 學一學(一說到挖一挖,那麼問題來了,挖掘機技術到底哪家強
Android源碼的結構
bionic 目錄– libc (C庫)| |– arch-arm (ARM架構,包含系統調用匯編實現)| |– arch-x86 (