Android 发出多个Json请求
我想在一个活动中发出7个JSON请求。有什么办法吗?Android 发出多个Json请求,android,json,Android,Json,我想在一个活动中发出7个JSON请求。有什么办法吗? 如果有任何方法可以使用volley实现它?您可以通过设置它们的标记来运行parallelJSONObjectRequests。例如,假设您希望使用循环发送请求。您将执行以下操作: for (int i = 0; i < requestSize; i++) { StringRequest request = new StringRequest(Request.Method.POST, AppUrls
如果有任何方法可以使用volley实现它?您可以通过设置它们的标记来运行parallel
JSONObjectRequest
s。例如,假设您希望使用循环发送请求。您将执行以下操作:
for (int i = 0; i < requestSize; i++)
{
StringRequest request = new StringRequest(Request.Method.POST,
AppUrls.URL_SAVE_SAVE_DATA, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String status = "";
JSONObject json = null;
try {
json = new JSONObject(response);
if(json != null && json.has(JSONParsor.STATUS))
status = json.getString(JSONParsor.STATUS);
if(status != null && status.length() > 0 && status.equalsIgnoreCase("success"))
{
}
else {
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
})
{
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put(JSONParsor.DATA_STRING, jsonObject.toString());
return params;
}
};
request.setTag("TAG_" + i);
addToRequestQueue(request);
}
for(int i=0;i0&&status.equalsIgnoreCase(“成功”)
{
}
否则{
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
}
})
{
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
参数put(JSONParsor.DATA_字符串,jsonObject.toString());
返回参数;
}
};
request.setTag(“TAG_u”+i);
addToRequestQueue(请求);
}
作为响应,您可以返回请求id,然后可以匹配,哪个请求属于哪个标记
希望这能有所帮助。请展示您的努力。7 JSON请求非常大。你试过什么?