com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期 BEGIN_OBJECT 但在第 1 行第 2 列路径 $ 处为 STRING

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $

我在使用改造将 json 数组发布到服务器时遇到此错误。我的 json 是有效的,因为我通过在线工具
检查了相同的内容 这是我发布的 json

[
  {
  "image":"/9j/4AAQ//Z",
  "pole_code":"Adv234",
  "latitude":28.62628851,
  "longitude":77.37868293,
  "vendor_name":"1"
  }
]


这是发布相同

的方法
@POST("SyncPole")
Call<SyncApiResponse>uploadSurveyData(@Body JsonArray array);


制作JsonArray的代码

private JsonArray createJsonArray(List<PoleSurveyData> list){
    JsonArray jsonArray = new JsonArray();
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            JsonObject jsonObject = new JsonObject();
            try {
                String imgString = Base64.encodeToString(list.get(i).getImage(),
                        Base64.NO_WRAP);
                jsonObject.addProperty("image", imgString);
                jsonObject.addProperty("pole_code", list.get(i).getPoleCode());
                jsonObject.addProperty("latitude", list.get(i).getLatitude());
                jsonObject.addProperty("longitude", list.get(i).getLongitude());
                jsonObject.addProperty("vendor_name","1");

                jsonArray.add(jsonObject);

                ;

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

        }
}
return jsonArray;
}


我已点击这些链接 ,但其中 none 有效
邮递员请求的屏幕截图
谁能帮我解决我做错的地方

"success"

您在 Response 中获得 String,但您期望 SyncApiResponse 中的 object。这就是问题所在

解决方法:您必须更改响应格式。像下面的结构。

{
 "status": "success",
 "message": "demo message"
}