2017-09-26 7 views
0

私はJSONをretieves Webサービスにアプリケーションを接続しようとしているにJSONを充電するが、JSONExceptionを返すためにの問題は私のAndroidのアプリケーション、JSONException

マイコード:

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

Logcatの画像を見てください。

enter image description here

+0

あなたはjsonレスポンスを投稿しますか? –

+0

oyuはdownloadUrlで何をしているのですか? –

+0

ここにhttps://pruebasmartunes.000webhostapp.com/pruebas_getMp3StreamTitle.php –

答えて

1

あなたが解析しようとしているJSONはcancio」と呼ばれる配列フィールドを持っていないので、あなたはその例外を取得していますn "である。私はリンクされたlogcatイメージでJSON全体を見ることができません(次回は、スクリーンショットではなく質問の中のテキストを含む方が良い)、私が見ることができるものから、フィールド名はスペイン語ではなく英語で可視フィールドのいずれも配列ではありません。

これでJSON全体が含まれていました。私はcancionがJSONArrayではなくJSONObjectであることがわかりました。

+0

私はかなり初心者です。このリンクのJSON構造を見てください:https://pruebasmartunes.000webhostapp.com/pruebas_getMp3StreamTitle.php –

+0

{"cancion":{"タイトル": "Versace On The Floor(Vs David Guetta)"、 "artist": "BRUNO MARS "、" duration ":" 18783 "}} –

+1

私の回答を編集しました。 "cancion"は配列ではなくJsonObjectです。 – Chris

関連する問題