我正在开发一个与我编写的RESTful Web服务进行通信的Android应用程序。使用Volley进行GET方法时,表的名称很棒且容易,但是我不能把手指放在他没有表名的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 + "\n\n");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(reques);
}
}
答案 0 :(得分:0)
看起来你得到一个JSONArray作为响应,在这种情况下你需要使用JSONArrayRequest。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler