第一个JAVABEAN:
public class ResultRules {
private String gTaskId;
private int ulRet;
private String execStatus;
private int ulRetParam1;
private int ulRetParam2;
private int ulTaskStatus;
private String cmdName;
private int nNUms;
private List<Rules> rules;
public String getgTaskId() {
return gTaskId;
}
public void setgTaskId(String gTaskId) {
this.gTaskId = gTaskId;
}
public int getUlRet() {
return ulRet;
}
public void setUlRet(int ulRet) {
this.ulRet = ulRet;
}
public String getExecStatus() {
return execStatus;
}
public void setExecStatus(String execStatus) {
this.execStatus = execStatus;
}
public int getUlRetParam1() {
return ulRetParam1;
}
public void setUlRetParam1(int ulRetParam1) {
this.ulRetParam1 = ulRetParam1;
}
public int getUlRetParam2() {
return ulRetParam2;
}
public void setUlRetParam2(int ulRetParam2) {
this.ulRetParam2 = ulRetParam2;
}
public int getUlTaskStatus() {
return ulTaskStatus;
}
public void setUlTaskStatus(int ulTaskStatus) {
this.ulTaskStatus = ulTaskStatus;
}
public String getCmdName() {
return cmdName;
}
public void setCmdName(String cmdName) {
this.cmdName = cmdName;
}
public int getnNUms() {
return nNUms;
}
public void setnNUms(int nNUms) {
this.nNUms = nNUms;
}
public List<Rules> getRules() {
return rules;
}
public void setRules(List<Rules> rules) {
this.rules = rules;
}
}
第二个JAVABEAN:
public class Rules {
private int nSnmpTry;
private int nSnmpVersion;
private String szCommunity;
private int nType;
private int nCurrentTick;
private String szParam;
private String szOid;
private int PollTime;
private String szUpdateTime;
private String szCreateTime;
private String szSnmpIP;
private int ID;
private int nSnmpTimeOut;
private int nSnmpPort;
public int getnSnmpTry() {
return nSnmpTry;
}
public void setnSnmpTry(int nSnmpTry) {
this.nSnmpTry = nSnmpTry;
}
public int getnSnmpVersion() {
return nSnmpVersion;
}
public void setnSnmpVersion(int nSnmpVersion) {
this.nSnmpVersion = nSnmpVersion;
}
public String getSzCommunity() {
return szCommunity;
}
public void setSzCommunity(String szCommunity) {
this.szCommunity = szCommunity;
}
public int getnType() {
return nType;
}
public void setnType(int nType) {
this.nType = nType;
}
public int getnCurrentTick() {
return nCurrentTick;
}
public void setnCurrentTick(int nCurrentTick) {
this.nCurrentTick = nCurrentTick;
}
public String getSzParam() {
return szParam;
}
public void setSzParam(String szParam) {
this.szParam = szParam;
}
public String getSzOid() {
return szOid;
}
public void setSzOid(String szOid) {
this.szOid = szOid;
}
public int getPollTime() {
return PollTime;
}
public void setPollTime(int pollTime) {
PollTime = pollTime;
}
public String getSzUpdateTime() {
return szUpdateTime;
}
public void setSzUpdateTime(String szUpdateTime) {
this.szUpdateTime = szUpdateTime;
}
public String getSzCreateTime() {
return szCreateTime;
}
public void setSzCreateTime(String szCreateTime) {
this.szCreateTime = szCreateTime;
}
public String getSzSnmpIP() {
return szSnmpIP;
}
public void setSzSnmpIP(String szSnmpIP) {
this.szSnmpIP = szSnmpIP;
}
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public int getnSnmpTimeOut() {
return nSnmpTimeOut;
}
public void setnSnmpTimeOut(int nSnmpTimeOut) {
this.nSnmpTimeOut = nSnmpTimeOut;
}
public int getnSnmpPort() {
return nSnmpPort;
}
public void setnSnmpPort(int nSnmpPort) {
this.nSnmpPort = nSnmpPort;
}
public Rules() {
}
public Rules(int nSnmpTry, int nSnmpVersion, String szCommunity, int nType, int nCurrentTick, String szParam, String szOid, int pollTime, String szUpdateTime, String szCreateTime, String szSnmpIP, int iD, int nSnmpTimeOut, int nSnmpPort) {
super();
this.nSnmpTry = nSnmpTry;
this.nSnmpVersion = nSnmpVersion;
this.szCommunity = szCommunity;
this.nType = nType;
this.nCurrentTick = nCurrentTick;
this.szParam = szParam;
this.szOid = szOid;
this.PollTime = pollTime;
this.szUpdateTime = szUpdateTime;
this.szCreateTime = szCreateTime;
this.szSnmpIP = szSnmpIP;
this.ID = iD;
this.nSnmpTimeOut = nSnmpTimeOut;
this.nSnmpPort = nSnmpPort;
}
调用代码:
JSONArray jsonArray = JSONArray.fromObject(result);
Map<String, Class> map = new HashMap<String, Class>();
map.put("rules", Rules.class);
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
ResultRules resultRules = (ResultRules) jsonObject.toBean(jsonObject, ResultRules.class, map);
System.out.println(resultRules.getUlTaskStatus());
}
报错情况如下:
net.sf.json.JSONException: java.lang.NoSuchMethodException: Unknown property 'rules' on class 'class com.smonitor.bean.ResultRules'
at net.sf.json.util.PropertySetStrategy$DefaultPropertySetStrategy._setProperty(PropertySetStrategy.java:69)
at net.sf.json.util.PropertySetStrategy$DefaultPropertySetStrategy.setProperty(PropertySetStrategy.java:60)
at net.sf.json.JSONObject.setProperty(JSONObject.java:1394)
at net.sf.json.JSONObject.toBean(JSONObject.java:422)
at net.sf.json.JSONObject.toBean(JSONObject.java:252)
at com.smonitor.web.CommandAction.doPost(CommandAction.java:74)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoSuchMethodException: Unknown property 'rules' on class 'class com.smonitor.bean.ResultRules'
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2133)
at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:890)
at net.sf.json.util.PropertySetStrategy$DefaultPropertySetStrategy._setProperty(PropertySetStrategy.java:67)
... 19 more
相关推荐
//字符串json转换成json, 根据情况是用JSONArray或JSONObject @Test public void testJsonStrToJSON(){ JSONArray jsonArray = JSONArray.fromObject( "['json','is','easy']" ); System.out.println( ...
JSON中的值可以是七种类型:对象、数组、数字、字符串、布尔值(true或false)、null以及任意由这七种类型组合而成的复合类型。 JSON在前后端数据交互中的应用非常广泛,因为它易于构建和解析,且与语言无关。前端...
使用`@RestController`标记的类,其方法返回的对象会直接转换成JSON格式响应给客户端。 3. `@RequestBody`:用于将HTTP请求体中的数据反序列化为Java对象,通常配合控制器方法的参数使用。 4. `@RequestMapping`:...
10.4.1 Spring通过单实例化Bean简化多线程问题 10.4.2 启动独立线程调用事务方法 10.5 联合军种作战的混乱 10.5.1 Spring事务管理器的应对 10.5.2 Hibernate+Spring JDBC混合框架的事务管理 10.6 特殊方法成漏网之鱼...
10.4.1 Spring通过单实例化Bean简化多线程问题 10.4.2 启动独立线程调用事务方法 10.5 联合军种作战的混乱 10.5.1 Spring事务管理器的应对 10.5.2 Hibernate+Spring JDBC混合框架的事务管理 10.6 特殊方法成漏网之鱼...
MongoDB是一种NoSQL数据库,以JSON-like的BSON格式存储数据,适合处理大量非结构化或半结构化的数据。 3. **配置Spring Data MongoDB** 配置Spring Data MongoDB主要包括设置MongoDB连接信息(如主机名、端口、...
- 支持 JSON 数据格式。 #### 2. Axis2 版本 - **1.x 和 2.x 系列**: - **1.x 系列**: 基于 Axis1.x 的改进版。 - **2.x 系列**: 重新设计的版本,提供了更多的功能和更好的性能。 - **本文重点**: 使用 2.x ...
- **示例:** `renderJson(json)`返回JSON格式的数据。 #### 五、AOP **5.1 概述** - **功能介绍:** AOP(面向切面编程)是JFinal中提供的增强功能,可以用于日志记录、性能监控等方面。 **5.2 Interceptor** ...
{1.8.1.3}复合赋值运算}{28}{subsubsection.1.8.1.3} {1.8.2}逻辑运算}{29}{subsection.1.8.2} {1.8.3}条件运算符}{29}{subsection.1.8.3} {1.8.4}移位运算符}{30}{subsection.1.8.4} {1.9}流程控制}{31}{...