2017-12-26 2 views
0

db에서 데이터를 가져 와서 텍스트를 설정하려고합니다. 값을 가져오고 URL에 표시하지만 setText가 작동하지 않습니다. JSONObject도 동일한 문제가 발생했습니다. 나는 어디로 잘못 가고 있니? 아래는 내 코드와 백엔드 출력입니다.json volley를 사용하여 데이터를 가져 오는 중

{ 
"status": 200, 
"db": { 
    "test_count": 2539, 
    "franchise_count": 2, 
    "patient_count": 1, 
    "invoice_count": 1, 
    "total_income": "12140", 
    "current_income": "12140", 
    "total_expense": null, 
    "current_expense": null, 
    "user_count": 2 
}} 

JsonObjectRequest objectRequest = new JsonObjectRequest(Request.Method.GET, url, 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        progressDialog.dismiss(); 
        try { 
           JSONObject object = new JSONObject(); 
           u = object.getString("user_count"); 
           user_count.setText(u); 

        } catch (JSONException e) { 
         Toast.makeText(getContext(),"No Records Found",Toast.LENGTH_LONG); 
         Log.e("Error", "Failed" +e.toString()); 
         e.printStackTrace(); 
        } 
       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        progressDialog.dismiss(); 
        Log.e("Error", "Try Later" +error.toString()); 
        Toast.makeText(getContext(),"No Records Found",Toast.LENGTH_LONG); 
       } 
      }); 
    RequestQueue requestQueue = Volley.newRequestQueue(getActivity()); 
    requestQueue.add(objectRequest); 
} 

답변

1
  new Response.Listener<JSONObject>() { 
      @Override 
      public void onResponse(JSONObject response) { 
       progressDialog.dismiss(); 
       try { 
          JSONObject newObject=response.getJSONObject("db"); 
          u = newObject.getString("user_count"); 
          user_count.setText(u); 

       } catch (JSONException e) { 
        Toast.makeText(getContext(),"No Records Found",Toast.LENGTH_LONG); 
        Log.e("Error", "Failed" +e.toString()); 
        e.printStackTrace(); 
       } 
      } 
+0

u를 감사

아래처럼 try 블록의 내용을 변경

! 그것의 작동 –

+0

다행 :) –

관련 문제