我的是要读本地的json文件 怎么读都是乱码
各种犯难 ,到最后 解决了 原来那么简单....
解决方法如下:
代码:
/**
* 获取Assets路径下的文件
*
* @param context
* @param fileName
* @return
*/
public static String getJson(Context context, String fileName) {
String json = "";
try {
AssetManager s = context.getAssets();
try {
InputStream is = s.open("data.json");
byte[] buffer = new byte[is.available()];
is.read(buffer);
json = new String(buffer, "utf-8");
is.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(json);
return json;
}
这是读取文件的方法
如果怎么读都是乱码 就打开你要解析的文件
然后另存为,然后设置编码成utf-8就OK了