2014-08-28 23 views
1

我試圖使用volley將JSON對象發送到服務器並得到響應,但似乎服務器不能獲取數據。服務器在android上使用volley時沒有收到JSON對象

如果我試圖只回顯它的工作原理,但如果我嘗試讀取服務器上的JSON對象並作出反應,我會在抽頭中得到錯誤。我也嘗試回顯JSON對象並仍然出錯。 當我使用HttpRequest時,一切正常。 我添加了與HttpRequest和Volley中相同的頭文件,也許已連接到UTF8?這是我做setEntity

我得到這樣的PHP數據:

$data = json_decode(file_get_contents('php://input'), true); 

我凌空代碼:

JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, 
      URL, jsonObject , 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 

         Log.d(TAG,"Response: " + response.toString()); 

       } 
      }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        VolleyLog.e("Error: ", error.getMessage()); 
       } 
      }) 
      {  
       @Override 
       public Map<String, String> getHeaders() throws AuthFailureError { 
         Map<String, String> params = new HashMap<String, String>(); 
         params.put("Accept", "application/json"); 
         params.put("Content-Type", "application/json"); 

         return params; 
       } 
      }; 
    ; 

人有一個想法?

+0

你可以試試gson ... – KOTIOS 2014-08-28 17:28:51

+0

出於興趣你會發現只有Object.class類型的Treturn類型?另外,什麼是排球錯誤?最後:使用error.printStackTrace()代替 – Breadbin 2014-08-28 17:38:20

+1

我面臨同樣的問題。你有沒有辦法解決? – ik024 2014-09-19 12:18:40

回答

0

事實證明,我的排球代碼是好的。問題出在服務器端。

使用Breadbin註釋並用error.printStackTrace()替換VolleyLog.e幫助查找問題。

相關問題