W/System.err: at com.android.volley.toolbox.JsonObjectReques



我正在开发一个Android应用程序,可以与我编写的RESTful Web服务进行通信。将 Volley 用于 GET 方法,ho 表的名称很棒且简单,但我无法将手指放在他没有表名称的 get 方法上

我如何从我的帖子请求的响应中获取字段这是我的响应

enter code here
[
{
"fullname": "IDRISS SAMI",
"accountnumber": "0825005896788",
"rib": "10403082500589678844",
"iban": "",
"name": "COMPTE SPECIAL EPARGNE",
"balance": "1462,6580"
},
{
"fullname": "IDRISS SAMI",
"accountnumber": "0821006348788",
"rib": "10403082100634878827",
"iban": "",
"name": "COMPTE CHEQUE",
"balance": "6105,5590"
}

] 这是我的代码

enter code here
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject employee = jsonArray.getJSONObject(i);
String firstName = response.getString("fullname");
int age = employee.getInt("accountnumber");
String mail = employee.getString("name");
Toast.makeText(ActivityUserProfile.this, "ok"+firstName, Toast.LENGTH_LONG).show();

mTextViewResult.append(firstName + ", " + String.valueOf(age) + ", " + mail + "nn");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(reques);
}

}

看起来你得到了一个JSONArray作为响应,在这种情况下,你需要使用JSONArrayRequest。

JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET,
URL,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
//this method returns the json array
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//this method is called if any error in fetching jsonArray
}
});

最新更新