JAVA----百度推广接口返回结果集统一处理

JAVA----百度推广接口返回结果集统一处理,第1张

JAVA----百度推广接口返回结果集统一处理 获取百度推广接口返回数据结果集统一处理

百度api code

0:成功,
1:部分失败
2:全部失败
3:系统错误
	private static final Integer SUCCESS_CODE = 0;  // 0:成功,1:部分失败,2:全部失败,3:系统错误
    private static final String SUCCESS_DESC = "success";

    
    public static AjaxResult getResult(String res) {
        if (StringUtils.isEmpty(res)) {
            return AjaxResult.error("返回数据为空");
        }

        JSonObject jsonObject = JSONObject.parseObject(res);
        JSonObject header = jsonObject.getJSonObject("header");
        Integer code = header.getInteger("status");
        String desc = header.getString("desc");

        if (code == SUCCESS_CODE && desc.equals(SUCCESS_DESC)) {
            JSonArray data = jsonObject.getJSonObject("body").getJSonArray("data");
            return AjaxResult.success("", data);
        }

        return AjaxResult.error(code, header.getString("failures"));
    }

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5694664.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存