JSONObject 响应为空
JSONObject response null
我正在尝试使用 Volley JsonObjectRequest
发送简单的 JSON request
。
获得 JSON response
后,我想更新一个名为 valoreConvertito
的值,但 JSON 响应为 null
,因此 valoreConvertito
仍为零。
private void convertiREST(final Double valoreDaConvertire, String valuta){
final TextView textView = (TextView) findViewById(R.id.text);
RequestQueue queue = Volley.newRequestQueue(this);
String url =COMPLETEURL;
valoreConvertito = 0.0;
JsonObjectRequest objectRequest = new JsonObjectRequest(
Request.Method.GET,
url,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Log.e("Rest response ", response.toString());
valoreConvertito = response.getJSONObject("quotes").getDouble("valuta");
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Rest response", error.toString());
}
});
queue.add(objectRequest);
}
我什至遵循了另一个 post () 中的建议,但我仍然得到 JSON 无效响应。
使用调试器似乎程序在 onResponse nor
和 ErrorListener
中都没有输入。
添加行 queue.add(objectRequest);
后,我注意到 Logcat 中的 HTTP traffic not permitted
错误,我已经解决了 post 之后的问题。
我正在尝试使用 Volley JsonObjectRequest
发送简单的 JSON request
。
获得 JSON response
后,我想更新一个名为 valoreConvertito
的值,但 JSON 响应为 null
,因此 valoreConvertito
仍为零。
private void convertiREST(final Double valoreDaConvertire, String valuta){
final TextView textView = (TextView) findViewById(R.id.text);
RequestQueue queue = Volley.newRequestQueue(this);
String url =COMPLETEURL;
valoreConvertito = 0.0;
JsonObjectRequest objectRequest = new JsonObjectRequest(
Request.Method.GET,
url,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Log.e("Rest response ", response.toString());
valoreConvertito = response.getJSONObject("quotes").getDouble("valuta");
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Rest response", error.toString());
}
});
queue.add(objectRequest);
}
我什至遵循了另一个 post (
使用调试器似乎程序在 onResponse nor
和 ErrorListener
中都没有输入。
添加行 queue.add(objectRequest);
后,我注意到 Logcat 中的 HTTP traffic not permitted
错误,我已经解决了