首页 > 编程语言 > 详细

json字符串转成 json对象 json对象转换成java对象

时间:2019-06-19 10:59:16      阅读:296      评论:0      收藏:0      [点我收藏+]
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;


依赖包

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.54</version>
</dependency>





String result = ""; //下面是把拿到的json字符串转成 json对象 JSONObject jsStr = JSONObject.parseObject(requestBody); //将字符串{“id”:1} //int jsID = Integer.parseInt(jsStr.getString("id"));//获取id的值 /** * json对象转换成java对象 */ InvestorApplyModel stud = (InvestorApplyModel) JSONObject.toJavaObject(jsStr,InvestorApplyModel.class); }




/** 
* json字符串转转换成json数组 
*/
 
String schedules = "";
JSONArray schedulesArray= JSONArray.parseArray(schedules);
JSONObject jostr = null;

for (int sched = 0; sched <schedulesArray.size() ; sched++) {

//获取json对象
jostr = schedulesArray.getJSONObject(0);
//System.out.println("jostr---" + jostr);

/** 
* json对象转换成java对象 
*/

BerthStop berthStopDo = (BerthStop) JSONObject.toJavaObject(jostr, BerthStop.class);








 

json字符串转成 json对象 json对象转换成java对象

原文:https://www.cnblogs.com/JonaLin/p/11049865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!