I'm trying to get a json file from remote host and parsing it via GSON.
Therefore I'm calling my function
private void initData() {
placeArrayList = PlaceRepository.getPlaceList();
}
In my PlaceRepository-class
public static ArrayList<Place> getPlaceList() {
return new Gson().fromJson(json, new TypeToken<ArrayList<Place>>(){}.getType());
}
and the referenced json is a static string:
static String json = "[\n" +
" {\n" +
" \"id\":\"GardensByTheBay\",\n" + ...
Thats absoluty working. But now I would like to use remote json data from my server.
I'm sure that I have to use something like asynctask, right? Because I tried to load the json file and it failed with an NetworkOnMainThreadException.
Thank you!