13

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

他の誰かがこれに問題を抱えていますか?

リストビューを作成できるように JSON をハッシュマップに入れたいのですが、JSON から logcat にデータを取得できません。

ご挨拶

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

1 に答える 1