JAVA之JSON字符串转换实体类

Posted 二零一七

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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":"否"
}
]
}
]
}
}

























































































以上是关于JAVA之JSON字符串转换实体类的主要内容,如果未能解决你的问题,请参考以下文章

java将JSON字符串转换为实体类对象,基于net sf json实现

JSON-JSON字符串转换成JSON对象JSON对象数组java实体类以及保存到List列表中

java 怎么把正常时间转换成json类型的

怎么把hashmap转换成实体类

二维数组和json对象的转换

eclipse如何打开实体类输入json字符串插件