JAVA之JSON字符串轉換實體類


@Override
public String getExamPaper(String examID, String userID) throws Exception{
String strResult;
ExamQuestion entity;

strResult = examObjectStudentRep.getExamPaper(examID, userID);
entity = JSON.parseObject(JSON.parse(strResult).toString(),ExamQuestion.class);

return examObjectStudentRep.getExamPaper(examID, userID);
}

/////////////
JSON格式的String字符串

{
"service":{
"count":"20",
"item":[

{
"id":"EES_SS1830738",
"type":"1",
"question":"題目1",
"value":"5",
"rightanswer":"3",
"option":[
{
"id":"1",
"description":"答案"
},
{
"id":"2",
"description":"答案2"
},
{
"id":"3",
"description":"答案2"
},
{
"id":"4",
"description":"建議書"
}
]
},
{
"id":"EES_MS0654246",
"type":"2",
"question":"題目",
"value":"5",
"rightanswer":"1,3,4",
"option":[
{
"id":"1",
"description":"12321321"
},
{
"id":"2",
"description":"12321321 "
},
{
"id":"3",
"description":"12321312"
},
{
"id":"4",
"description":"12321"
}
]
},
{
"id":"EES_JU0561902",
"type":"3",
"question":"12312312",
"value":"5",
"rightanswer":"0",
"option":[
{
"id":"1",
"description":"是"
},
{
"id":"0",
"description":"否"
}
]
}
]
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM