这是Volley功能。我使用了数组,并且有多个值,例如arra [] = {1,2,4,5}我希望使用parameter.put(“Data”,array [])发送此数组,这将如何发生?
public void sendData(){
requestQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> parameters = new HashMap<String, String>();
for(int i =0;i<array.length;i++) {
String A= array[i].toString();
parameters.put("Generated",A);
}
return parameters;
}
};
requestQueue.add(request);
}
答案 0 :(得分:0)
您可能需要将gson转换为json。
添加您的图书馆。
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
然后
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.setDateFormat("yyyy-MM-dd HH:mm:ss").create();
parameters.put("Generated",gson.toJson(array));