我有一個我想變成JSON的類,但構造函數不允許我。該類稱爲CourseKeyInfo:在java中將bean轉換爲Json
public class CourseKeyInfo
{
private String courseKey;
private String institutionID;
public CourseKeyInfo(String courseKey, String institutionId)
{
this.courseKey = courseKey;
this.institutionID = institutionId;
}
public String getCourseKey()
{
return courseKey;
}
public void setCourseKey(String courseKey)
{
this.courseKey = courseKey;
}
public String getInstitutionID()
{
return institutionID;
}
public void setInstitutionID(String institutionID)
{
this.institutionID = institutionID;
}
}
我用JSONObject body = new JSONObject(responseEntity);
把它變成JSON,但它給我「的構造函數的JSONObject(CourseKeyInfo)是未定義」的錯誤。任何想法如何我可以把我的課變成json?
難道這個API使用的是http://www.json.org/javadoc/org/json/JSONObject.html? – Nishant 2012-07-27 17:09:01
如果是這樣,它應該支持這個http://www.json.org/javadoc/org/json/JSONObject.html#JSONObject%28java.lang.Object%29它在構造函數 – Nishant 2012-07-27 17:11:09
中需要Object Nishant你是對的。我使用的是Jettison實現,我沒有使用正確的API。我將其更改爲org.json並且它工作正常。 – user1558274 2012-07-27 17:21:17