JSON.parseObject的幾種用法


JSON.parseObject的幾種用法

 

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


免責聲明!

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



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