gpt4 book ai didi

java - 实现 JsonObjectRequest 时遇到问题

转载 作者:行者123 更新时间:2023-12-02 03:38:08 25 4
gpt4 key购买 nike

我在实现 JsonObjectRequest 以从网络获取 JsonObject 时遇到问题。我正在尝试创建一个新的 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 studio 用红色突出显示的波浪线,上面写着

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

有人知道出了什么问题吗?

最佳答案

试试这个方法:

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) {

}
});

关于java - 实现 JsonObjectRequest 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37184832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com