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());
    }

相关文章:

  • 2021-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-02-05
  • 2021-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-11
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2021-11-04
相关资源
相似解决方案