2016-01-06 2 views
8

jsonのサーバーからデータを取得するためのコードが起動していないと思います。 logcatには、 "log.v"のテキストはありません。また、私が作ったコードは、いつもtry catchでうまくいかないようです。私はAjaxリクエストにAqueryを使用します。AqueryのajaxリクエストがAndroidで起動していないようです

他にもこの問題がありますか?

私はそれのリストビューを構築することができるようにハッシュマップにJSONを入れたいが、私は

Greathings logcatにPhoneGapので

public class film_sound extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     // Get the view from fragmenttab1.xml 
     View view = inflater.inflate(R.layout.activity_film_sound, container, false); 
     Context context = inflater.getContext(); 
     String[] Film_Data = getArguments().getStringArray("Film_Data"); 

     File ext = Environment.getExternalStorageDirectory(); 
     File cacheDir = new File(ext, "/android/data/be.moviechecker.programma/case"); 
     AQUtility.setCacheDir(cacheDir); 
     final AQuery aq = new AQuery(context); 

     /*Ophalen van de json*/ 
     String url = "http://app.be/data_2_0_0/sound.php?id=1"; 
     aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() { 
      @Override 
      public void callback(String url, JSONObject json, AjaxStatus status) { 
       if (json != null) { 
        JSONArray jArray = null; 
        try { 
         jArray = json.getJSONArray("soundtrack"); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 

        if (jArray.length() == 0) { 
         Log.v("debug", "dataleeg"); 
        } else { 
         for (int i = 0; i < jArray.length(); i++) { 
          JSONObject json_data = null; 
          try { 
           json_data = jArray.getJSONObject(i); 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
          try { 
           Log.v("debug", json_data.getString("naam")); 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
         } 
        } 
       } else { 
        //ajax error, show error code 
        Log.v("debug", aq.getContext() + "Error:" + status.getCode()); 
       } 
      } 
     }); 

     return view; 
    } 
} 
+1

間違ったURLを使用しているようです。ブラウザでURLを開こうとしてください(コピー+貼り付け)。返されるjsonデータはありません。このページが見つからないというエラーだけです。 'AQuery'が返されたデータをjsonにキャストしようとしているのと同じ理由で、何も返されなかったり、ログに記録されたりしていません。適切なURLを使用してjsonデータを取得してください。 – rom4ek

+1

これは本当のURLではありません、私はPHPコード – user3142817

+1

からステータス200とjsonを取得しますので、** real ** urlを投稿すると、コミュニティはその問題を再現する必要があるため、解決できるようにすべての情報が必要です。あなたの問題。 – rom4ek

答えて

0

あなたが持っているが、JSONからデータを取得カントに多分config.xmlに

<access origin="http://domain.com/public/auth/app-login"/> 

yのクロスドメイン要求を有効にしますあなたはこれを見ることができます:
WebView Javascript cross domain from a local HTML file