Почему ничего не приходит с api
private class GetHotels extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL("http://10.0.2.2:64325/api/Hotels");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder result = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null) {
result.append(line);
}
return result.toString();
} catch (Exception ex) {
return null;
}
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
try {
JSONArray tempArray = new JSONArray(s); // Почему приходит сюда Null
for (int i = 0; i < tempArray.length(); i++) {
JSONObject hotelJson = tempArray.getJSONObject(i);
Hotel tempHotel = new Hotel(
hotelJson.getInt("Id"),
hotelJson.getString("Name"),
hotelJson.getInt("CountOfStars"),
hotelJson.getString("HotelImage")
);
mHotelsList.add(tempHotel);
mAdapter.notifyDataSetChanged();
}
} catch (Exception e) {
}
}
}