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

错误原因:

/**
*请求
*/
@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 parameterMap = new HashMap();
            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> i = entrySet().iterator();
        if (! i.hasNext())
            return "{}";

        StringBuilder sb = new StringBuilder();
        sb.append('{');
        for (;;) {
            Entry 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(' ');
        }
    }

你可能感兴趣的:(Java)