com.android.volley.ParseError: org.json.JSONException: значение ... типа java.lang.Integer не может быть преобразовано в JSONObject - PullRequest
0 голосов
/ 13 марта 2019
    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. Как я могу решить эту ошибку?

- Правка: добавлен остаток кода -

...