欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

接口被调用 返回jsonArray 处理jsonArray数据

程序员文章站 2022-04-16 20:21:52
...
 
 @RequestMapping(value = "/querySource.htm", method = RequestMethod.POST)
public String init(HttpServletRequest request ) throws IOException {

Map<String, String> map = new HashMap<String, String>();
        Enumeration<?> fields = request.getParameterNames();

        while(fields.hasMoreElements())
        {
            String field = (String) fields.nextElement();
            String[] values = request.getParameterValues(field);
            if (values.length > 1)
                map.put(field, values.toString());
            else
                map.put(field, values[0]);
        }
        logger.info("***接口返回jsonArray:"+map.get("jsonArray"));




if(map.get("jsonArray")!=null && map.get("jsonArray").length()>0){
 String arrayStr = map.get("jsonArray");

            List<PostAccountVO> postAccountVOList = new ArrayList<PostAccountVO>();

            List<Map<String,String>> listObjectSec = JSONArray.parseObject(arrayStr,List.class);
            Map<String,String> mapList = new HashMap<String, String>();
            for(int i=0;i<listObjectSec.size();i++){
                mapList = listObjectSec.get(i);
                JSONObject jsonObject = JSONObject.fromObject(mapList);
                PostAccountVO postAccountVO=(PostAccountVO)JSONObject.toBean(jsonObject, PostAccountVO.class);
                postAccountVOList.add(postAccountVO);
            }
            logger.info("接口jsonArray数据转对象:"+postAccountVOList);


}


}

对方是以http的方式访问我的就接口