public class JsonResolutionUtils {
/**
* 得到json文件中的内容
* @param context
* @param fileName
* @return
*
* 使用:
* responseData = JsonResolutionUtils.getJson(Activity.this, "bookstore_man.json");
* cityVo = JSON.parseObject(responseData, CityVo.class);
正常解析
*/
public static String getJson(Context context, String fileName){
StringBuilder stringBuilder = new StringBuilder();
//获得assets资源管理器
AssetManager assetManager = context.getAssets();
//使用IO流读取json文件内容
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
assetManager.open(fileName),"utf-8"));
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line.trim());
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
}
转自某篇文章(已找不到出处,如有人知晓请告诉我,会附上原创链接)
网友评论