【发布时间】:2014-07-02 13:23:26
【问题描述】:
我有一个数据类列表。是否可以将此列表转换为 JSONArray ? 我的数据类:
public class Data {
// private variables
int _id;
String _objectID;
String _objectIDServer;
String _type;
String _date;
String _json;
// Empty constructor
public Data() {
}
// constructor
public Data(int id) {
this._id = id;
}
// constructor
public Data(String objectID, String json) {
this._objectID = objectID;
this._json = json;
}
// constructor
public Data(int id, String type, String date, String json) {
this._id = id;
this._type = type;
this._date = date;
this._json = json;
}
// constructor
public Data(String objectID, String objectIDServer, String type,
String date, String json) {
this._objectID = objectID;
this._objectIDServer = objectIDServer;
this._type = type;
this._date = date;
this._json = json;
}
// constructor
public Data(int id, String objectID, String objectIDServer, String type,
String date, String json) {
this._id = id;
this._objectID = objectID;
this._objectIDServer = objectIDServer;
this._type = type;
this._date = date;
this._json = json;
}
// constructor
public Data(String objectID, String type, String date, String json) {
this._objectID = objectID;
this._type = type;
this._date = date;
this._json = json;
}
// constructor
// public Data(int id, String objectID, String type, String date, String
// json) {
// this._id = id;
// this._objectID = objectID;
// this._type = type;
// this._date = date;
// this._json = json;
// }
// getting ID
public int getID() {
return this._id;
}
// setting id
public void setID(int id) {
this._id = id;
}
// getting ID
public String getIDServer() {
return this._objectIDServer;
}
// setting id
public void setIDServer(String objectIDServer) {
this._objectIDServer = objectIDServer;
}
// getting type
public String getObjectID() {
return this._objectID;
}
// setting type
public void setObjectID(String objectID) {
this._objectID = objectID;
}
// getting type
public String getType() {
return this._type;
}
// setting type
public void setType(String type) {
this._type = type;
}
// getting data
public String getDate() {
return this._date;
}
// setting date
public void setDate(String date) {
this._date = date;
}
// getting ID
public String getJson() {
return this._json;
}
// setting id
public void setJson(String json) {
this._json = json;
}
}
我得到这样的列表:
DatabaseDataHandler db = new DatabaseDataHandler(getApplicationContext());
List<Data> list = db.getAllData();
过去几个小时我尝试了很多不同的方法,但都没有奏效。 任何帮助将不胜感激..
【问题讨论】: