0

I have trying to connect a application to web services that retrieves a JSON, but return JSONException

My code:

private class LlenarDatosReproduccion extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        try {
            return downloadUrl(urls[0]);
        } catch (IOException e) {
            return "Ups! Error.Parece que la url es inválida";
        }
    }

    @Override
    protected void onPostExecute(String result) {
        try {
            JSONObject responseJSON = new JSONObject(result.toString());
            JSONArray cancionJSON = responseJSON.getJSONArray("cancion");
            tvTitle.setText(cancionJSON.getString(1));
            //tvArtist.setText(cancionJSON.getString(2));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        super.onPostExecute(result);
    }
}

Please look the Logcat image

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Endy Bermúdez R
  • 351
  • 1
  • 2
  • 8

1 Answers1

1

You're getting that exception because the JSON you are attempting to parse does not have an array field called "cancion". I can't see the whole JSON in the logcat image you linked (next time, you're better off including the text in your question rather than a screenshot), from what I can see, the field names are in English not Spanish and none of the visible fields are arrays.

Now that you included the whole JSON: I can see that cancion is a JSONObject not a JSONArray.

Chris
  • 22,923
  • 4
  • 56
  • 50