2016-05-12 65 views
0

我在執行JsonObjectRequest時遇到問題,因爲您在網上獲取JsonObject。 我想創建一個新的JsonObjectRequest在執行JsonObjectRequest時遇到問題

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        try { 

         JSONObject ratesJsonObj = response.getJSONObject("rates"); 
         String RON = ratesJsonObj.getString("RON"); 

         Log.v("Currency", RON); 

        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 

       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 

     } 
    }); 

但一切這一切都彎彎曲曲的下由Android工作室紅色白標明的,它說

Error:(41, 47) error: reference to JsonObjectRequest is ambiguous, both constructor 
JsonObjectRequest(int,String,String,Listener<JSONObject>,ErrorListener) 
in JsonObjectRequest and constructor 
JsonObjectRequest(int,String,JSONObject,Listener<JSONObject>,ErrorListener) 
in JsonObjectRequest match 

沒有人有任何的想法有什麼不對?

回答

2

試試這個方法:

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, (JSONObject) null, 
     new Response.Listener<JSONObject>() { 
      @Override 
      public void onResponse(JSONObject response) { 
       try { 

        JSONObject ratesJsonObj = response.getJSONObject("rates"); 
        String RON = ratesJsonObj.getString("RON"); 

        Log.v("Currency", RON); 

       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 

      } 
     }, new Response.ErrorListener() { 
    @Override 
    public void onErrorResponse(VolleyError error) { 

    } 
}); 
+0

坦克很多@Oleg Khalidov ... thtat小投我抱回:) – Adrian

0

演員空字符串,它會工作。 (字符串)null