有時候可能會用到json格式進行數據的傳輸
json數據
兩個VO類
public class SurveyVO {
private String surveyId;
private String surveyName;
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
ssage = message;
}
public String getSurveyId() {
return surveyId;
}
public void setSurveyId(String surveyId) {
this
}
public String getSurveyName() {
return surveyName;
}
public void setSurveyName(String surveyName) {
this
}
}
public class SurveyListVO {
private String message;
private List<SurveyVO> result;
public String getMessage() {
return message;
}
public void setMessage(String message) {
ssage = message;
}
public List<SurveyVO> getResult() {
return result;
}
public void setResult(List<SurveyVO> result) {
this
}
}
json格式轉換成object類型
public class fromGson() {
sTotalString = {
Gson gson = new Gson()
SurveyListVO surveyListVO = gson
SurveyListVO
for (int i =
System
print:
System
print: B///C
System
}
}
json數據
一個VO類
public class SurveyVO {
private String surveyId;
private String surveyName;
public String getSurveyId() {
return surveyId;
}
public void setSurveyId(String surveyId) {
this
}
public String getSurveyName() {
return surveyName;
}
public void setSurveyName(String surveyName) {
this
}
}
json格式轉換成object類型
public class fromJson() {
sTotalString = {
JSONObject json;
try {
json = new JSONObject(sTotalString)
JSONArray results = json
for (int i =
SurveyVO surveyVO = new SurveyVO()
JSONObject result = results
System
surveyVO
surveyVO
surveyVOList
}
} catch (JSONException e) {
e
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25754.html