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