我正在尝试转换一个对象,并且该对象具有一个 ArrayList 对象,该对象具有属性和一个整数。
但是当我在 JSON 对象上使用 toString() 时,我得到的是指针而不是对象:
{"class":"class model.ListResult","listVideo":["model.Video@706a4d1a","model.Video@52ec1f9e","model.Video@c0fe89a","model.Video@686fdca5","model.Video@7ff0a34","model.Video@78f6e005","model.Video@17eda64e","model.Video@73415727","model.Video@46c0fc8e"],"numberOfResult":109}
这是我的课程的代码:
public class ListResult implements Serializable {
private int numberOfResult;
private ArrayList<Video> listVideo;
/**
* Constructor
*
* @param allVideoNumber
* @param listVideo2
*/
public ListResult(int numberOfResult, ArrayList<Video> listVideo) {
this.numberOfResult = numberOfResult;
this.listVideo = listVideo;
}
public int getNumberOfResult() {
return numberOfResult;
}
public void setNumberOfResult(int numberOfResult) {
this.numberOfResult = numberOfResult;
}
public ArrayList<Video> getListVideo() {
return listVideo;
}
public void setListVideo(ArrayList<Video> listVideo) {
this.listVideo = listVideo;
}
}
我的方法调用:
public String getListJson(boolean escape, int from, int number, String order, String by, ArrayList<Category> listCategory) throws Exception {
//get list of video
ArrayList<Video> listVideo = dbVideo.getAll(from, number, order, by, listCategory);
JSONObject jsObject = new JSONObject(new ListResult(dbVideo.getAllVideoNumber(listCategory), listVideo));
if(escape) {
String r;
r = jsObject.toString();
r = r.replace("\\", "\\\\");
r = r.replace("'", "\\'");
return r;
}
return jsObject.toString();
}