zoukankan      html  css  js  c++  java
  • String类型转json 转JSONObject 转 JSONArray 以及 遍历

       public PageVo getByPage(int pageNum, int pageSize) {
            PageVo pageVo = new PageVo();
            System.out.println("web " + pageNum);
            System.out.println("web " + pageSize);
            List<Map<String, Object>> getCurrentiJDByPage = iSearchService.getCurrentiJDByPage(pageNum, pageSize);
            List<Map<String ,Object>> newList =new ArrayList();
            for (Map<String, Object> jdMap :getCurrentiJDByPage) {
                Map<String, Object> content = (Map) JSON.parse((String) jdMap.get("content"));
                Map<String, Object> map = new HashMap<>();
                JSONObject obj = (JSONObject) content.get("workExec");
                JSONObject education = (JSONObject) content.get("education");
                JSONObject position = (JSONObject) content.get("position");
                JSONObject monthScale = (JSONObject) content.get("monthScale");
                JSONArray welfareArray = (JSONArray) content.get("welfare");
                JSONObject skill = (JSONObject)content.get("skill");
                    for (int i = 0; i < welfareArray.size(); i++) {
                        JSONObject welfare = welfareArray.getJSONObject(i);
                        map.put("welfareName"+i, welfare.get("name"));
                    }
                Map<String, String> params = JSONObject.parseObject(obj.toJSONString(), new TypeReference<Map<String, String>>() {
                });
                Map<String, Object> educationParam = JSONObject.parseObject(education.toJSONString(), new TypeReference<Map<String, Object>>() {
                });
                Map<String, Object> positionParam = JSONObject.parseObject(position.toJSONString(), new TypeReference<Map<String, Object>>() {
                });
                Map<String, String> monthScaleParam = JSONObject.parseObject(monthScale.toJSONString(), new TypeReference<Map<String, String>>() {
                });
                Map<String, String> skillParam = JSONObject.parseObject(skill.toJSONString(), new TypeReference<Map<String, String>>() {
                });
                String database = skillParam.get("database");
                String devEnvironment = skillParam.get("devEnvironment");
                String devFrame = skillParam.get("devFrame");
                String importantDto = skillParam.get("importantDto");
    
                JSONObject important = (JSONObject)JSONObject.parse(importantDto);
                 JSONArray devLanguage = (JSONArray) important.get("devLanguage");
                 JSONArray modelAlgo = (JSONArray) important.get("modelAlgo");
    
                JSONArray parse = (JSONArray)JSONArray.parse(database);
                JSONArray environment = (JSONArray)JSONArray.parse(devEnvironment);
                JSONArray frame = (JSONArray)JSONArray.parse(devFrame);
                for (int i = 0; i < environment.size(); i++) {
                    JSONObject json = environment.getJSONObject(i);
                    map.put("devEnvironment"+i, json.get("name"));
                }
                for (int i = 0; i < devLanguage.size(); i++) {
                    JSONObject json = devLanguage.getJSONObject(i); // 遍历 jsonarray 数组,把每一个对象转成 json 对象
                    map.put("devLanguage"+i, json.get("name"));
                }
                for (int i = 0; i < modelAlgo.size(); i++) {
                    JSONObject json = modelAlgo.getJSONObject(i); // 遍历 jsonarray 数组,把每一个对象转成 json 对象
                    map.put("modelAlgo"+i, json.get("name"));
                }
                for (int i = 0; i < frame.size(); i++) {
                    JSONObject json = frame.getJSONObject(i);
                    map.put("frame"+i, json.get("name"));
                }
                for (int i = 0; i < parse.size(); i++) {
                    JSONObject json = parse.getJSONObject(i);
                    map.put("database"+i, json.get("name"));
                }
    
                Integer peopleSize = (Integer)jdMap.get("people_size");
                Integer financeStep = (Integer)jdMap.get("finance_step");
                switch (financeStep){
                    case  0 :
                        map.put("financeStep", ResumeScaleEnum.UNLIMITED.getMessage());
                        break;
                    case  1 :
                        map.put("financeStep", ResumeScaleEnum.PRE_A.getMessage());
                        break;
                    case  2 :
                        map.put("financeStep", ResumeScaleEnum.PRE_B.getMessage());
                        break;
                    case  3 :
                        map.put("financeStep", ResumeScaleEnum.PRE_C.getMessage());
                        break;
                    case  4 :
                        map.put("financeStep", ResumeScaleEnum.PRE_D.getMessage());
                        break;
                    case  5 :
                        map.put("financeStep", ResumeScaleEnum.PRE_ANGEL.getMessage());
                        break;
                    case  6 :
                        map.put("financeStep", ResumeScaleEnum.UN_FINANCE.getMessage());
                        break;
                    case  7 :
                        map.put("financeStep", ResumeScaleEnum.LISTED.getMessage());
                        break;
                    case  8 :
                        map.put("financeStep", ResumeScaleEnum.PRE_D_ABOVE.getMessage());
                        break;
                }
                switch (peopleSize){
                    case 0 :
                        map.put("peopleSize", ResumePeopleSizeEnum.UNLIMITED.getMessage());
                        break;
                    case 1 :
                        map.put("peopleSize", ResumePeopleSizeEnum.ONE.getMessage());
                        break;
                    case 2 :
                        map.put("peopleSize", ResumePeopleSizeEnum.TWO.getMessage());
                        break;
                    case 3 :
                        map.put("peopleSize", ResumePeopleSizeEnum.THREE.getMessage());
                        break;
                    case 4 :
                        map.put("peopleSize", ResumePeopleSizeEnum.FOUR.getMessage());
                        break;
                    case 5 :
                        map.put("peopleSize", ResumePeopleSizeEnum.FIVE.getMessage());
                        break;
                }
                String industryIds = (String) jdMap.get("industry_ids");
                String[] industryIdsArr = industryIds.split(",");
                String str = "";
                if (industryIdsArr != null && industryIdsArr.length > 0) {
                    for (int i = 0; i < industryIdsArr.length; i++) {
                        Industry industry = resumeService.getIndustryById(industryIdsArr[i]);
                        str +=  industry.getName()  + ",";
                    }
                }
                str = str.substring(0, str.length() - 1);
                map.put("industryName",str);
                map.put("id",jdMap.get("id"));
                map.put("logoUrl", jdMap.get("logo_url"));
                map.put("name", jdMap.get("name"));
                map.put("companyId", jdMap.get("company_id"));
                map.put("workAddress", content.get("workAddress"));
                map.put("workExec", params.get("name"));
                map.put("education", educationParam.get("name"));
                map.put("position", positionParam.get("name"));
                map.put("monthScaleSmall", monthScaleParam.get("small"));
                map.put("monthScaleBig", monthScaleParam.get("big"));
                newList.add(map);
            }
            pageVo.setList(newList);
            pageVo.setPs(pageSize);
            pageVo.setPn(pageNum);
            return pageVo;
        }
    
  • 相关阅读:
    nginx的一些
    索引
    liunx 里面安装phpstudy环境s
    Linux操作系统定时任务系统 Cron 入门
    Memcached的安装
    模拟php curl向远程服务器上传文件
    file_get_contens POST传值
    ab测试
    ASP.Net Core 3.1 发布错误 Error NU1605 解决方案
    Taker短信转发到HTTP POST接口的配置
  • 原文地址:https://www.cnblogs.com/cuixiaomeng/p/10007443.html
Copyright © 2011-2022 走看看