I followed a tutorial for an JSON Parser and tried to use it for another request with the same api. But now it always fails when trying to parse it to a JSON Object.
This is my JSON parser:
public class GetProvider extends AsyncTask<String, String, String> {
protected String doInBackground(String... params) {
String current = "";
String providerURL = "https://api.themoviedb.org/3/movie/" + model.getId() + "/watch/providers?api_key=" + api_key;
try {
URL url;
HttpURLConnection urlConnection = null;
try {
url = new URL(providerURL);
urlConnection = (HttpURLConnection) url.openConnection();
InputStream is = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
int data = isr.read();
while(data != -1) {
current += (char) data;
data = isr.read();
}
is.close();
return current;
} catch (IOException e) {
e.printStackTrace();
} finally {
if(urlConnection != null) {
urlConnection.disconnect();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return current;
}
@Override
protected void onPostExecute(String s) {
try {
JSONObject jsonObject = new JSONObject(s);
JSONArray jsonArray = jsonObject.getJSONArray("results");
for(int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
model.setProvider_id(jsonObject1.getString("provider_id"));
model.setProvider_name(jsonObject1.getString("provider_name"));
System.out.println("Stop");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
When running it fails with:
W/System: A resource failed to call end.
It doesn't even show the whole value. how can I get the whole value/fix that?