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":"张三"
}]
}
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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步