首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

list集合转换JSON出错误

2012-02-21 
list集合转换JSON出异常public void getstreet() {HttpServletRequest request ServletActionContext.ge

list集合转换JSON出异常
public void getstreet() {
HttpServletRequest request = ServletActionContext.getRequest();
String areaid = request.getParameter("areaid");
System.out.println("-------aid--------->" +listarea);
List<Street> listStreet = houseservice.listStreet(Integer.parseInt(areaid));
JSONObject jsonArray= JSONObject.fromObject(listStreet);}
这个是我方法listStreet 就是从数据库里面的到的值我用debug调式里面不为空有值
但是我用这个方法JSONObject jsonArray= JSONObject.fromObject(listStreet);的时候报出异常
严重: Servlet.service() for servlet default threw exception
net.sf.json.JSONException: 'object' is an array. Use JSONArray instead
at net.sf.json.JSONObject.fromObject(JSONObject.java:190)
at net.sf.json.JSONObject.fromObject(JSONObject.java:154)
at org.shj.houseproject.house.action.HouseAction.getstreet(HouseAction.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.j
不知道哪里出了问题

[解决办法]
'object' is an array. Use JSONArray instead

这句话多明显啊孩子。
让你用JSONArray方法。
[解决办法]

探讨
但是我jquery写的为什么报object is null

热点排行