|
发表于 2015-4-24 09:11:27
|
显示全部楼层
照样子写了个,可是这个j执行时出错
JSONObject obj=queryWaitTasks(request);是得到数据的 内容是对的
{"message":"","ext":"","flag":true,"stack":"","customer":"0","ver":"0","md5":"","code":"","reason":"","aCode":"","data":{"value":{"rows":[{"StartTime":{"changed":"0","value":"2015-04-23T14:58:00.000Z","originalValue":null},"TaskStateName":{"changed":"0","value":"执行中","originalValue":null},"Topic":{"changed":"0","value":"任务来了","originalValue":null},"t":{"changed":"0","value":"D54FBF4E9AE04A7DBC952F99D8CFC0B9","originalValue":null},"userdata":{"recordState":null},"Ratio":{"changed":"0","value":null,"originalValue":null}},{"StartTime":{"changed":"0","value":"2015-04-10T15:11:37.000Z","originalValue":null},"TaskStateName":{"changed":"0","value":"执行中","originalValue":null},"Topic":{"changed":"0","value":"第二个任务","originalValue":null},"t":{"changed":"0","value":"97A5762A0F984FF299DD09E6F0686E33","originalValue":null},"userdata":{"recordState":null},"Ratio":{"changed":"0","value":null,"originalValue":null}}],"@type":"table","userdata":{"relationTypes":"String,String,DateTime,String,Float","relationAlias":"t,Topic,StartTime,TaskStateName,Ratio","relations":"CRM_Task,CRM_Task.Topic,CRM_Task.StartTime,CRM_Task.TaskStateName,CRM_Task.Ratio","model":"/CRM/Common/data","updateMode":"whereVersion"}}},"guid":"0","messages":"[]"}
可是JSONObject data = obj.getJSONObject("data");就是报错
java.lang.ClassCastException: org.json.JSONObject$Null
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.justep.biz.client.Action;
import com.justep.biz.client.ActionEngine;
import com.justep.biz.client.ActionResult;
import com.justep.biz.client.ActionUtils;
import com.justep.ui.util.NetUtils;
public class MyTask extends com.justep.ui.impl.JProcessorImpl {
public static final String PROCESS = "/CRM/Common/process/Task/taskProcess";
public static final String ACTIVITY = "mainActivity";
private static final String QUERY_WAIT_TASK_ACTION = "MyTaskAction";
@Override
public void execute(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
try
{
String executor= NetUtils.getExecutor(request);
JSONObject obj=queryWaitTasks(request);
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter pw = response.getWriter();
//pw.println(obj);
JSONObject data = obj.getJSONObject("data");
//pw.println("OK!!");
JSONObject value=data.getJSONObject("value");
JSONArray array=value.getJSONArray("rows");
JSONObject rows=null;
pw.println("<html>");
pw.println("<head>");
pw.println("<link rel='stylesheet' type='text/css' href='/x5/UI/CRM/js/lixiang.css'>");
pw.println("<script type='text/javascript' src='/x5/base/base.js' ></script>");
pw.println("<script type='text/javascript' src='/x5/form/form.js' ></script>");
pw.println("<script type='text/javascript' src='/x5/UI/CRM/js/lixiang.js'></script>");
pw.println("</head>");
pw.println("<body>");
pw.println("<table width='100%'>");
for(int i=0;i<array.length();i++)
{
rows=array.getJSONObject(i);
JSONObject sTopicObj=rows.getJSONObject("Topic");
JSONObject sStartTimeObj=rows.getJSONObject("StartTime");
JSONObject sTaskStateNameObj=rows.getJSONObject("TaskStateName");
JSONObject sRatioObj=rows.getJSONObject("Ratio");
JSONObject sTaskIDObj=rows.getJSONObject("t");
String sTopic=(String) sTopicObj.get("value");
String sStartTime=(String) sStartTimeObj.get("value");
String sTaskStateName=(String) sTaskStateNameObj.get("value");
String sRatio=(String) sRatioObj.get("value");
String sTaskID=(String) sTaskIDObj.get("value");
pw.println("<tr style='font-size:12px;'>");
pw.println("<td style='width:12px;'>");
pw.println("<img name='flagImg' src='/x5/UI/SA/task/taskView/images/dot.png'></img>");
pw.println("</td>");
pw.println("<td class='className'>");
pw.print("<a href='javascript:void(0)' onclick=\"LMIS_OpenMyTask(\'");
pw.print(sTopic);
pw.print("\',\'");
pw.print(sTaskID);
pw.print("\',\'");
pw.print(executor);
pw.println("\')\">");
pw.println(sTopic);
pw.println("</a>");
pw.println("</td>");
pw.println("<td style='width:1px;'></td>");
pw.println("<td class='className' style='width:61px;'>");
pw.println(sTaskStateName+"("+sRatio+")");
pw.println("</td>");
pw.println("<td style='width:1px;'></td>");
pw.println("<td class='className' style='width:63px;'>");
pw.println(sStartTime.substring(0, 10));
pw.println("</td>");
pw.println("</tr>");
}
pw.println("</table>");
pw.println("</body>");
pw.println("</html>");
}
catch(JSONException e)
{
e.printStackTrace();
}
}
private JSONObject queryWaitTasks(HttpServletRequest request)
{
Action action = new Action();
action.setProcess(PROCESS);
action.setActivity(ACTIVITY);
action.setName(QUERY_WAIT_TASK_ACTION);
action.setExecutor(NetUtils.getExecutor(request));
action.setExecuteContext(NetUtils.getExecuteContext(request));
String bsessionID = NetUtils.getBSessionID(request);
String language = NetUtils.getLanguage(request);
ActionResult ar = ActionEngine.invokeAction(action, ActionUtils.JSON_CONTENT_TYPE, bsessionID, language, null);
return (JSONObject) ar.getContent();
} |
|