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

2021-04-25 05:28

阅读:468

标签:could   app   turn   city   code   nbu   work   exception   his   

 private List 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>() {
        }.getType());
    }

gson.fromJson(json, new TypeToken

标签:could   app   turn   city   code   nbu   work   exception   his   

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


评论


亲,登录后才可以留言!