码迷,mamicode.com
首页 > Web开发 > 详细

JSON.parseObject的几种用法

时间:2020-07-02 16:18:45      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:post   parse   cti   use   tor   string   add   lld   字符   

 

https://blog.csdn.net/a18827547638/article/details/80272099

https://blog.csdn.net/a18827547638/article/details/80777366

import com.alibaba.fastjson.JSONObject;

一.result格式:

{

    "success":"true";

"returnAddress":"123"

}
JSONObject jsonObject=JSON.parseObject(result); //转换成object

jsonObject.getString("returnAddress") //获取object中returnAddress字段; 
二.result格式:
{

"success":"true";

    "data":{

        "shop_uid":"123";
    };

}
 

JSONObject shop_user =JSON.parseObject(result);

JSON.parseObject(shop_user .getString("data")).getString("shop_uid")
三.result格式:

{

    "success":"true";

"data":[{

"shop_uid":"123";

},

{

"shop_name":"张三"

}]
}
 

  1. payload:{     
  2.     t: [{
  3.      id: 3004463, creator: "luojian", gmtCreated: 1584683688000, modifier: "luojian",…
  4.     }],
  5. count: 2}
/**把大的字符串转为json对象*/
JSONObject payload = JSONObject.parseObject(resultDO.getResultString()).getJSONObject("payload");
String count = payload.getString("count");
if(Integer.parseInt(count) > 0){

return JSONObject.parseArray(payload.getString("t"),FullDiscountQueryDTO.class);//Json字符串数据转换成集合对象

JSONArray detail = JSON.parseArray(result);
for (int i=0; i<detail.size();i++){
if(detail.get(i)!=null||!detail.get(i).equals("")){
JSONArray detailChild =detail.getJSONArray(i);
if(detailChild.getInteger(1)>Integer.valueOf(ship.get("shiptime").toString())){
ship.put("shiptime",detailChild.getInteger(1));
ship.put("desc",detailChild.getString(0));
}
}
}
JSON转javaBean

1.1 JSONobject=>javaBean

JSONObject contentChild = contentsArray.getJSONObject(i);
QCCustomerScore.CustomerCore customerCore = JSON
.toJavaObject(contentChild, QCCustomerScore.CustomerCore.class);
1.2 String转javaBean

JSON.parseObject的几种用法

标签:post   parse   cti   use   tor   string   add   lld   字符   

原文地址:https://www.cnblogs.com/guguanghu/p/13224968.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!