private void sendData(int id) throws JSONException {
RequestQueue queue = Volley.newRequestQueue(this);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String format = simpleDateFormat.format(new Date());
JSONObject jsonData = new JSONObject();
jsonData.put("stationId", id);
jsonData.put("patientId", Integer.parseInt(values.getID()));
jsonData.put("timestamp", format);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, postUrl + "/stations/signin", jsonData, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
headers.put("Accept", "*/*");
return headers;
}
};
queue.add(jsonObjectRequest);
}
我正在尝试将 json 发送到服务器接收响应代码,例如:(200) 作为 int。我该如何解决这个错误?
--编辑:添加了其余代码--