简单使用Gson解析SDcard中的Json文件

File file = new File(Environment.getExternalStorageDirectory(),"news.json");
		try {
			FileInputStream fileInputStream = new FileInputStream(file);
			byte[] bytes = new byte[fileInputStream.available()];
			fileInputStream.read(bytes);
			string = new String(bytes);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Gson gson = new Gson();
		News fromJson = gson.fromJson(string, News.class);
		ArrayList<data> data2 = fromJson.getResult().getData();

其中News.class 是一个文件的封装类

这样 会有在SD卡中的json文件解析成集合的形式 如果有需要 使用listview展示出来

猜你喜欢

转载自blog.csdn.net/weixin_41722852/article/details/82843596