Java代码
* 根据页面用户输入的信息形成 Answer 对象的List
* @param answers
* @param question_ids
* @param types
* @return
*/
privateList toAnswerList(String[] studenAnswers,int[] question_ids,
int[] types,int[] scores) {
List answerList =newArrayList();
if(studenAnswers!=null&& question_ids!=null&& types!=null&& scores!=null){
for(inti =0; i < studenAnswers.length; i++) {
Answer answer =newAnswer();
String studenAnswer = studenAnswers[i];
inttype = types[i];
intquestion_id = question_ids[i];
intscore = scores[i];
answer.setQuestion_id(question_id);
answer.setScore(score);
answer.setStudenAnswer(studenAnswer);
answer.setType(type);
answerList.add(answer);
}
}
returnanswerList;
}
/**
* 将一个json字串转为list
* @param props
* @return
*/
publicstaticList converAnswerFormString(String answer){
if(answer ==null|| answer.equals(""))
returnnewArrayList();
JSONArray jsonArray = JSONArray.fromObject(answer);
List list = (List) JSONArray.toCollection(jsonArray,
Answer.class);
returnlist;
}
/**
*
* 将一个 Answer 对象的List 生成Json字串
* 是根据客户端页面用户输入的信息生成的
*
*
*/
publicString getAnswerString(String[] studenAnswers,int[] question_ids,
int[] types,int[] scores) {
List list = toAnswerList(studenAnswers, question_ids,
types, scores);
JSONArray jsonarray = JSONArray.fromObject(list);
returnjsonarray.toString();
}