为什么我的凌空从django rest api接收不到json?

时间:2019-03-14 17:45:57

标签: android json django rest

因此,这是我的android代码和url应该正常工作,但不确定。 没有找到关于该主题的任何教程,所以我被卡住了! PS我只是菜鸟,这里只是想开始!

private void fetchingJSON() {
    StringRequest stringRequest = new StringRequest(Request.Method.GET, "http://192.104.43.97/languages", new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("strrrrr", ">>" + response);
            try {
                JSONArray array = new JSONArray(response);

                //traversing through all the object
                for (int i = 0; i < array.length(); i++) {

                    //getting product object from json array
                    JSONObject product = array.getJSONObject(i);

                    //adding the product to product list
                    dataModelArrayList.add(new testmodel(
                            product.getInt("id"),
                            product.getString("url"),
                            product.getString("name"),
                            product.getString("paradigm")
                    ));
                    setupRecycler();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    //displaying the error in toast if occurrs
                    Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
    // request queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

0 个答案:

没有答案