Feign 调用出现的net.sf.json.exception:Unquotted String错误,解决办法。

来源:互联网 发布:mysql 5.1.65.tar.gz 编辑:程序博客网 时间:2024/05/16 08:43

错误原因:

/***请求*/@ResponseBody    @RequestMapping(value = "/queryMobileChainClinicCount.do", method = RequestMethod.POST)    public Object queryMobileChainClinicCount(String clinicID, String openID) {        logger.begin();        logger.debug("queryMobileChainClinicCount Parameters", clinicID);        ResultMessage message = new ResultMessage();        try {            Map<String, String> parameterMap = new HashMap<String, String>();            parameterMap.put("clinicID", clinicID);            parameterMap.put("openID", openID);            Integer count = mobileLoginService.queryMobileChainClinicCount(parameterMap);//feign 服务接口            message.setCode(CodeConstant.SUCCESS);            message.setData(count);            logger.debug("message", message);        } catch (BusinessException e) {            message.setCode(e.getErrorCode());            message.setCodeDesc(e.getErrorDes());            logger.error(e);        } catch (Exception e) {            message.setCode(CodeConstant.SYSTEM_ERROR);            message.setCodeDesc(ResourceUtils.getResultCodeDesc(CodeConstant.SYSTEM_ERROR));            logger.error(e);        }        logger.end();        return message;    }

原因是使用hashMap,在传输过程中hashMap的toString方法不会添加引号,于是在接收参数做json转换出现了如上问题,解决方法将HashMap替换成JSONObject

HashMap toString

public String toString() {        Iterator<Entry<K,V>> i = entrySet().iterator();        if (! i.hasNext())            return "{}";        StringBuilder sb = new StringBuilder();        sb.append('{');        for (;;) {            Entry<K,V> e = i.next();            K key = e.getKey();            V value = e.getValue();            sb.append(key   == this ? "(this Map)" : key);            sb.append('=');            sb.append(value == this ? "(this Map)" : value);            if (! i.hasNext())                return sb.append('}').toString();            sb.append(',').append(' ');        }    }
阅读全文
0 0
原创粉丝点击