博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java中JSON之全
阅读量:4580 次
发布时间:2019-06-09

本文共 6048 字,大约阅读时间需要 20 分钟。

1.           在不知道你要转的对象的类型的时候,用com.alibaba.fastjson.JSON.parse();

       Object parse = com.alibaba.fastjson.JSON.parse(response);

            System.out.println("parse的类型::::::"+parse.getClass());

2.    如果对象为list数组类型[], 用com.alibaba.fastjson.JSON.parseArray();
            com.alibaba.fastjson.JSONArray parseArray = com.alibaba.fastjson.JSON.parseArray(response);

 

下面出示一段代码:

package com.awspaas.user.apps.hh500.job;import java.util.List;import java.util.Map;import net.sf.json.JSONArray;import org.json.JSONException;import org.quartz.Job;import org.quartz.JobExecutionContext;import com.actionsoft.bpms.bo.engine.BO;import com.actionsoft.bpms.server.UserContext;import com.actionsoft.bpms.util.DBSql;import com.actionsoft.bpms.util.UtilString;import com.actionsoft.sdk.local.SDK;import com.awspaas.user.apps.hh500.util.WebService;public class SwanInterfaceJob implements Job {    private static WebService webService = null;    @Override    public void execute(JobExecutionContext jec) {        try {            getTestDataUser();            getTestDataKpi();        } catch (JSONException e) {            e.printStackTrace();        }    }    @SuppressWarnings("unchecked")    public String getTestDataUser() throws JSONException {        String URL = "http://192.168.1.240:8080/honghu/synchronizInterfaceController.do?getOrg";        webService = new WebService();        Map
userData = webService.request(URL, "{\"mainData\": \"测试组织架构\"}"); JSONArray jsonArray = null; if (!UtilString.isEmpty(userData.get("response"))) { DBSql.update("DELETE FROM BO_EU_ORG_INTERFACE"); String response = userData.get("response").toString(); Object parse = com.alibaba.fastjson.JSON.parse(response); System.out.println("parse的类型::::::"+parse.getClass()); System.out.println(parse); // com.alibaba.fastjson.JSONArray parseArray = com.alibaba.fastjson.JSON.parseArray(response);// System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"+parseArray); jsonArray = JSONArray.fromObject(parse.toString()); List
> aList = (List
>) jsonArray; List
bos = new java.util.ArrayList
(); BO bo = null; for (Map
RowJson4 : aList) { if (RowJson4.get("userMap") != null) { Map
map = (Map
) RowJson4.get("userMap"); if (map.get("id") != null) { for (Map
RowJson3 : aList) { if (RowJson3.get("orgType").toString().equals("3") && RowJson4.get("pId").toString().equals(RowJson3.get("id"))) { for (Map
RowJson2 : aList) { if (RowJson2.get("orgType").toString().equals("2") && RowJson3.get("pId").toString().equals(RowJson2.get("id"))) { for (Map
RowJson1 : aList) { if (RowJson1.get("orgType").toString().equals("1") && RowJson2.get("pId").toString().equals(RowJson1.get("id"))) { bo = new BO(); bo.set("COMPANY_ID", RowJson1.get("id"));// 公司ID bo.set("COMPANY_NAME", RowJson1.get("name"));// 公司 bo.set("DEPT_ID", RowJson2.get("id"));// 部门ID bo.set("DEPT_NAME", RowJson2.get("name"));// bo.set("POST_ID", RowJson4.get("id"));// 岗位ID bo.set("POST_NAME", RowJson4.get("name"));// bo.set("USER_ID", map.get("empNo"));// 人员账号 bo.set("USER_NAME", map.get("name")); bos.add(bo); } } } } } } } } } System.out.println(bos); if (bos != null && bos.size() > 0) { SDK.getBOAPI().createDataBO("BO_EU_ORG_INTERFACE", bos, UserContext.fromUID("admin")); } } return jsonArray.toString(); } @SuppressWarnings("unchecked") public void getTestDataKpi() throws JSONException { String URL = "http://192.168.1.240:8080/honghu/synchronizInterfaceController.do?getKpi"; net.sf.json.JSONArray jsonArray = null; webService = new WebService(); Map
userData = webService.request(URL, "{\"mainData\": \"测试指标\"}"); List
bos = new java.util.ArrayList
(); if (!UtilString.isEmpty(userData.get("response"))) { DBSql.update("DELETE FROM BO_EU_WEIGHT_INTERFACE"); String response = userData.get("response").toString(); Object parse = com.alibaba.fastjson.JSON.parse(response); System.out.println("parse的类型::::::"+parse.getClass()); System.out.println(parse); jsonArray = net.sf.json.JSONArray.fromObject(parse); System.out.println(jsonArray); List
> aList = (List
>) jsonArray; BO bo = null; for (Map
RowJson4 : aList) if ((!UtilString.isEmpty(RowJson4.get("type"))) && RowJson4.get("type").toString().equals("4")) { for (Map
RowJson3 : aList) { if ((!UtilString.isEmpty(RowJson3.get("type"))) && RowJson3.get("type").toString().equals("3") && RowJson4.get("parentId").toString().equals(RowJson3.get("id"))) { for (Map
RowJson2 : aList) { if ((!UtilString.isEmpty(RowJson2.get("type"))) && RowJson2.get("type").toString().equals("2") && RowJson3.get("parentId").toString().equals(RowJson2.get("id"))) { for (Map
RowJson1 : aList) { if ((!UtilString.isEmpty(RowJson1.get("type"))) && RowJson1.get("type").toString().equals("1") && RowJson2.get("parentId").toString().equals(RowJson1.get("id"))) { bo = new BO(); bo.set("WID", RowJson4.get("id"));// 指标ID // bo.set("FIRSTTYPE", RowJson1.get("firstType"));//一级指标 bo.set("FIRSTTYPE", RowJson1.get("projectName"));// 一级指标 bo.set("FIRST_CODE", RowJson1.get("projectCode")); // bo.set("MAXTYPE", RowJson2.get("maxType"));//二级指标 bo.set("MAXTYPE", RowJson2.get("projectName"));// 二级指标 bo.set("MAXTCODE", RowJson2.get("projectCode")); // bo.set("MINTYPE", RowJson3.get("minType"));//三级指标 bo.set("MINTYPE", RowJson3.get("projectName"));// 三级指标 bo.set("MINCODE", RowJson3.get("projectCode")); bo.set("PROJECTNAME", RowJson4.get("projectName"));// 四级指标 bo.set("PROJECTCODE", RowJson4.get("projectCode")); bo.set("NO", RowJson4.get("no"));// 排序序号 bo.set("REMAK", RowJson4.get("remak"));// 备注 bo.set("AFFILIATIONDPTNAME", RowJson4.get("affiliationDptName"));// 归属部门 bo.set("DUTYDPTNAME", RowJson4.get("dutyDptName"));// 责任部门 bos.add(bo); } } } } } } } } System.out.println(bos); if (bos != null && bos.size() > 0) { SDK.getBOAPI().createDataBO("BO_EU_WEIGHT_INTERFACE", bos, UserContext.fromUID("admin")); } }}

 

转载于:https://www.cnblogs.com/renpei/p/9857257.html

你可能感兴趣的文章
Asp.Net操作WebServices
查看>>
Linux基础命令----smbclient
查看>>
测试用例设计方法及增加新字段测试方法
查看>>
hrbust 1491 网络流一般增广路
查看>>
软件-开发工具:Gradle
查看>>
2019.7.4 打卡第五天
查看>>
day06数据类型----元组、字典、集合
查看>>
while循环(break、continue)
查看>>
luogu P4137 Rmq Problem / mex 主席树 + 思维
查看>>
C++编程思想,几个宏的用法:
查看>>
j-3. foreach ,for of ,for in-------待续
查看>>
数据仓库系列4-范式2
查看>>
Docker: docker container常用命令实战(2)-数据持久化
查看>>
C#编写自动关机程序复习的知识
查看>>
Yahoo!网站性能最佳体验的34条黄金守则——服务器
查看>>
国内4G频段划分
查看>>
20120104登陆与改密码
查看>>
How Does Caching Work in AFNetworking? : AFImageCache & NSUrlCache Explained
查看>>
UITableViewCell背景色.选中背景色,分割线,字体颜色设置
查看>>
MyBatis笔记一:GettingStart
查看>>