我正在尝试使用Volley在POST请求中以下列格式发送项目列表,但服务器正在接收空。
这是我的模型类:
public class SaveSettingsBO {
private int Id;
private String Key;
private int Value;
public SaveSettingsBO(int id, String key, int value) {
this.Id = id;
this.Key = key;
this.Value = value;
}
public int getId() {
return Id;
}
public void setId(int id) {
this.Id = id;
}
public String getKey() {
return Key;
}
public void setKey(String key) {
this.Key = key;
}
public int getValue() {
return Value;
}
public void setValue(int value) {
this.Value = value;
}
}
Java代码:
List<SaveSettingsBO> paramsList = new ArrayList<>();
paramsList.add(new SaveSettingsBO(0, "Paymentmethod", 1));
Gson gson = new Gson();
HashMap<String, Object> serviceParams = new HashMap<String, Object>();
serviceParams.put("accountSettingList", gson.toJson(paramsList));
是否有正确的方法在请求中发送数组?
或者我们应该将请求修改为以下内容:
答案 0 :(得分:0)
尝试使用此代码转换为Gson数组
Yazi <input type="text" id="yazi" value="">
<button onclick="ElaveEt();">OK</button>
<div id="list"></div>
<script>
function ElaveEt() {
if (document.getElementById("yazi").value.c.length > null) {
objYazi = document.getElementById("yazi");
objList = document.getElementById("list");
objList.innerHTML = objList.innerHTML + '<div id="Step">'+ objYazi.value + '<button onclick="YaziniSil();" >Sil</button>' + '<div>';
//document.getElementById("list").innerHTML = document.getElementById("list").innerHTML + '<br>' + document.getElementById("yazi").value;
document.getElementById("yazi").value = null;
} else {
alert('Boş xana əlavə oluna bilməz!')
}
}
function YaziniSil() {
document.getElementById("Step").remove();
}
</script>
并将其转换为字符串。