首页 > Web开发 > 详细

gson.fromJson(json, new TypeToken<List<City>

时间:2020-01-23 09:29:51      阅读:169      评论:0      收藏:0      [点我收藏+]
 private List<City> loadCities() {
        // In this case we‘re loading from local assets.
        // NOTE: could alternatively easily load from network.
        // However, that would need to happen on a background thread.
        InputStream stream;
        try {
            stream = getAssets().open("cities.json");
        } catch (IOException e) {
            return null;
        }

        Gson gson = new GsonBuilder().create();

        JsonElement json = new JsonParser().parse(new InputStreamReader(stream));

        return gson.fromJson(json, new TypeToken<List<City>>() {
        }.getType());
    }

gson.fromJson(json, new TypeToken<List<City>

原文:https://www.cnblogs.com/endv/p/12230076.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!