Unirest没有正确创建json字符串

时间:2018-05-29 17:40:08

标签: unirest

我创建了一个小型REST API,并希望在Java中使用它。我将Unirest添加到我的POM文件中并尝试了最简单的示例,但它不会起作用。

        try {
        HttpResponse<JsonNode> jsonResponse = Unirest.post(URL + "employees/comments")
                .header("accept", "application/json")
                .field("text", "Good job")
                .field("timestamp", "123455677777")
                .field("senderId", "5")
                .field("receiverId", "2")
                .asJson();

    } catch (UnirestException e) {
        e.printStackTrace();
    }

这会引发异常:

com.mashape.unirest.http.exceptions.UnirestException: java.lang.RuntimeException: java.lang.RuntimeException: org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]

据我了解,json格式有问题,但应该解决这个问题吗? http://unirest.io/java.html

0 个答案:

没有答案