admin管理员组

文章数量:1794759

JSONObject.parseObject syntax error,expect START WITH { OR [,but actually START WITH error

JSONObject.parseObject syntax error,expect START WITH { OR [,but actually START WITH error 解析JSON出现异常(JSON返回结果)

请求的url格式错误: 正确的:https://服务的IP:端口 /接口名称 ?参数列表 错误的:https://服务的IP:端口 ?参数列表

排查方法:可以将接口请求的返回结果打印出来,如果不是json的字符串,在做转换的时候,会报该错误。

代码语言:javascript代码运行次数:0运行复制
ResponseData responseData =  JSONObject.parseObject(responseStr,ResponseData.class);

public class ResponseData<T> {
    private static final long serialVersionUID = 6898451165550538312L;
    @AutoDocProperty("返回代码")
    private String resCode;
    @AutoDocProperty("返回消息")
    private String resMsg;
    @AutoDocProperty("返回实体")
    private T data;
}

//如果对接收到的json串转换为对象,需要将接收类具体化,而不是T泛型的方式。
ResponseGps responseData = JSON.parseObject(responseStr, ResponseGps.class);

public class ResponseGps {
    private String resCode;
    private String resMsg;
    private GpsVo data;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2023-02-09,如有侵权请联系 cloudcommunity@tencent 删除syntax服务接口errorexpect

本文标签: