请教java对象集合用json转换成字符串的问题

如题,我在用JSONArray.fromObject()将对象集合转换成字符串的时候给我报了个如下图的异常图片说明
这个异常是我用debug走到下面这段代码时抛出的

 JSONArray jsonArray=JSONArray.fromObject(ypyizhuList);//抛出异常的代码
            String aa=jsonArray.toString();

其中ypyizhuList是一个对象集合。
为了大神忙好帮我解决问题,现将主要的代码贴出,希望有高手帮我解决下,自己实在不知道该怎么解决了,代码如下

 import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.pb.entity.Qtfy;
import com.pb.util.Ypyznr;

public class CycfAction extends ActionSupport {
    private String feibie;
    private String lczhenduan;
    private String kebie;
    private String mark;
    private List<Ypyznr> ypyizhuList;
    private List<Qtfy> qtfyyizhuList;
    private Ypyznr ypyznr=new Ypyznr();
    private Qtfy qtfy=new Qtfy();


    public String cycf(){
        HttpServletRequest request = ServletActionContext.getRequest();
        String[] ypyizhu=request.getParameterValues("ypyizhu");
        String[] qtfyyizhu=request.getParameterValues("qtfyyizhu");
        ypyizhuList=new ArrayList<Ypyznr>();
        qtfyyizhuList=new ArrayList<Qtfy>();
        for(int i=0;i<ypyizhu.length;i++){
            String[] objypyizhu=ypyizhu[i].split(",");

                ypyznr.setYpmc(objypyizhu[0]);
                ypyznr.setZddwsl(objypyizhu[1]);
                ypyznr.setZddw(objypyizhu[2]);
                ypyznr.setZxdwsl(objypyizhu[3]);
                ypyznr.setZxdw(objypyizhu[4]);
                ypyznr.setJe(objypyizhu[5]);
                ypyizhuList.add(ypyznr);

        }
        for(int a=0;a<qtfyyizhu.length;a++){
            String[] objqtfyyizhu=qtfyyizhu[a].split(",");
            qtfy.setQtfymc(objqtfyyizhu[0]);
            qtfy.setQtfyje(objqtfyyizhu[1]);
            qtfyyizhuList.add(qtfy);
        }
            JSONArray jsonArray=JSONArray.fromObject(ypyizhuList);//抛出异常的代码
            String aa=jsonArray.toString();
            JSONArray jsonArraytow=JSONArray.fromObject(qtfyyizhuList);
            String bb=jsonArraytow.toString();
            System.out.println(aa);
            System.out.println(bb);
            return "success";
    }

我怀疑是jar包的问题,但是不知道是不是jar包有问题,现把所有的jar包也贴出来吧,望高手帮忙看下,所有jar包如下图
图片说明
图片说明

2个回答

高手们我找到原因了,缺少了一个jar包,commons-lang.jar就是缺了这个jar,问题总算解决了

解析json需要用到5个jar
commons-beanutils.jar;
commons-httpclient.jar;
commons-lang.jar;
ezmorph.jar;不少人使用时会提示net.sf.ezmorph.xxx找不到,就是缺这个:
morph-1.0.1.jar

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐