我有一个APi,其数据格式如下
{
name:
no:
data: [
{
surname:
option:
another_option:
}
]
another:
}
我想以字符串形式发布我的数据,因为它是对象形式,我想更新一个对象中的arralist,但是我无法获取如何在“ data:”中发送数据,因为我无法了解如何在参数的数组列表中发布我的字符串值。不能有n。我的arraylist对象中没有数组列表。我无法获取如何发送或将数据放入POST方法,请帮帮我
这是我正在尝试的代码。
private void new_process() {
String URL = "http://117.240.196.238:8080/api/raid";
Log.i("response", URL);
StringRequest jsonObjRequest = new StringRequest(
Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("response_process", response);
Upload_work(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("volley", "Error" + error.getMessage());
Log.i("response_error", error.toString());
}
}) {
@Override
public String getBodyContentType() {
return "application/x-www-form-urlencoded; charset=UTF-8";
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
String lic_date, lic_letter, lic_copy, sale_date, sale_letterno, sale_copy, material_name, material_quantity, quantity_in, fir_num, fir_dates, fir_policestation, sample_code, sample_date; List<String> number = new ArrayList<>();
number.add(first_text);
number.add(second_text);
number.add(third_text);
params.put("name", name);
params.put("no.", number);
params.put("data", ?????); // how to pass my list of string number to this data
params.put("another", another);
return params;
}
};
RequestQueue queue = SingletonRequestQueue.getInstance(getApplicationContext()).getRequestQueue();
queue.add(jsonObjRequest);
}
private void Upload_work(String response) {
Log.i("response_Upload_work", response);
try {
JSONObject json = new JSONObject(response);
int success = json.getInt("success");
String msg = json.getString("message");
if (success == 1) {
JSONObject c = json.getJSONObject("data");
String messg = c.getString("message");
Toast.makeText(this, messg, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(ScrollingActivity.this, msg, Toast.LENGTH_LONG).show();
}
} catch (Exception ex) {
Log.i("responseNew m", "Exception : " + ex.toString());
}
}
经过2天的搜索,我成功获得了一个ans,首先必须创建一个对象,我必须向该对象发送数据,然后以数组形式发送该对象,然后使用参数将其发送。
JSONObject json2 = new JSONObject();
try {
json2.put("name", sample_date);
json2.put("value", sample_code);
} catch (JSONException e) {
e.printStackTrace();
}
JsonArray sample_obj = new JsonArray();
sample_obj.add(String.valueOf(json2));
// after that send jsonarray to params
params.put("Raid_Sample", sample_obj.toString());