解析本地json数据

步骤:

1.创建assets文件放入json数据

在这里插入图片描述

2.根据json创建bean类

3.解析成我们要的数据

try {
            InputStream inputStream = this.getAssets().open("lunyu.json");
            String streamToString = UtilsStream.convertStreamToString(inputStream);
            Gson gson=new Gson();
            lunYuBeanList = gson.fromJson(streamToString, new TypeToken<List<LunYuBean>>() {}.getType());
        } catch (Exception e) {
            Log.d(TAG, "initView: "+e.getMessage());
        }

猜你喜欢

转载自blog.csdn.net/sunweihao2019/article/details/107630294
今日推荐