json数据 data: {}
{ "code":200, "data":{ "accountNonExpired":true, "accountNonLocked":true, "authorities":[ { "authority":"ROLE_SYS_SMS_AGENT" }, { "authority":"ROLE_AUTHENTICATED" } ], "credentialsNonExpired":true, "customerId":4, "enabled":true, "firstLogin":false, "id":16, "modifyPass":false, "sysRoles":[ { "id":13, "roleCode":"ROLE_SYS_SMS_AGENT", "roleDesc":"代理商(行程短信)", "roleName":"代理商(行程短信)", "roleStatus":0 } ], "token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ1c2VTeXNUeXBlIjoiMiIsInVzZXJNb2JpbGUiOiIxMzcyMzc5NzIwOCIsInVzZXJGdWxsTmFtZSI6IuS4reS_oemAmiIsImN1c3RvbWVySWQiOjQsInVzZXJMb2dpbk5hbWUiOiJ6eHQiLCJpZCI6MTYsInVzZXJUeXBlIjoxLCJleHAiOjE2NTk5NzcyOTMsInN5c1JvbGVzIjoiUk9MRV9TWVNfU01TX0FHRU5UIn0.NhcPWgd6ya3KsZ3Uoi2rN-HBGl2vc78gkub4-_uBkEkACeC_6MUgyboHUMTBegWd3Mv2bWvE4MzHLN3bPwl1Uw", "useSysType":"2", "userDesc":"", "userEmail":"", "userFullName":"中信通", "userIde":"", "userLastIpStr":"113.68.154.21", "userLastTime":"2022-08-08 22:47:44", "userLoginName":"zxt", "userMobile":"13723797208", "userOpenid":"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQFy8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAySTVTSkZIaUZmeGsxXzhPTHh4Y1YAAgSo1u9hAwQgHAAA", "userStatus":0, "userType":1, "username":"zxt" }, "message":"登录成功" }
我现在要取json数据中token值
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; public class JsonUtil { public static void main(String[] args) { String result = "{"code":200,"data":{"accountNonExpired":true,"accountNonLocked":true,"authorities":[{"authority":"ROLE_SYS_SMS_AGENT"},{"authority":"ROLE_AUTHENTICATED"}],"credentialsNonExpired":true,"customerId":4,"enabled":true,"firstLogin":false,"id":16,"modifyPass":false,"sysRoles":[{"id":13,"roleCode":"ROLE_SYS_SMS_AGENT","roleDesc":"代理商(行程短信)","roleName":"代理商(行程短信)","roleStatus":0}],"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ1c2VTeXNUeXBlIjoiMiIsInVzZXJNb2JpbGUiOiIxMzcyMzc5NzIwOCIsInVzZXJGdWxsTmFtZSI6IuS4reS_oemAmiIsImN1c3RvbWVySWQiOjQsInVzZXJMb2dpbk5hbWUiOiJ6eHQiLCJpZCI6MTYsInVzZXJUeXBlIjoxLCJleHAiOjE2NTk5NzcyOTMsInN5c1JvbGVzIjoiUk9MRV9TWVNfU01TX0FHRU5UIn0.NhcPWgd6ya3KsZ3Uoi2rN-HBGl2vc78gkub4-_uBkEkACeC_6MUgyboHUMTBegWd3Mv2bWvE4MzHLN3bPwl1Uw","useSysType":"2","userDesc":"","userEmail":"","userFullName":"中信通","userIde":"","userLastIpStr":"113.68.154.21","userLastTime":"2022-08-08 22:47:44","userLoginName":"zxt","userMobile":"13723797208","userOpenid":"https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQFy8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAySTVTSkZIaUZmeGsxXzhPTHh4Y1YAAgSo1u9hAwQgHAAA","userStatus":0,"userType":1,"username":"zxt"},"message":"登录成功"}"; JSONObject jsonObject = JSON.parseObject(result); String msg = jsonObject.getString("data"); JSONObject jsonobj = JSON.parseObject(msg); String token = String.valueOf(jsonobj.get("token")); System.out.println("token: "+token); } }
输出
token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ1c2VTeXNUeXBlIjoiMiIsInVzZXJNb2JpbGUiOiIxMzcyMzc5NzIwOCIsInVzZXJGdWxsTmFtZSI6IuS4reS_oemAmiIsImN1c3RvbWVySWQiOjQsInVzZXJMb2dpbk5hbWUiOiJ6eHQiLCJpZCI6MTYsInVzZXJUeXBlIjoxLCJleHAiOjE2NTk5NzcyOTMsInN5c1JvbGVzIjoiUk9MRV9TWVNfU01TX0FHRU5UIn0.NhcPWgd6ya3KsZ3Uoi2rN-HBGl2vc78gkub4-_uBkEkACeC_6MUgyboHUMTBegWd3Mv2bWvE4MzHLN3bPwl1Uw
json数据 data: {[
{},
{}
]}
{ "code": 200, "message": "SUCCESS", "data": { "total": 2, "list": [ { "id": 3421, "uuid": "e35f905a35874ad0a7f04443bb4e0b59", "orderNo": "2022-GD-W-126", "agentId": 4, "agentName": "中信通", "advertiserName": "汕头市达阳广告传媒有限公司", "status": 0, "auditStat": 1, "createDate": "2022-08-09 17:39:10", "createId": 16, "materials": [ { "id": 9370, "billUuid": "e35f905a35874ad0a7f04443bb4e0b59", "regionNo": 1, "fileName": "1.微信推广素材1.jpg", "fileType": "jpg", "resourcesUrl": "/deliverywx/2022/05/30/a84841854502430ab51b41233728a6ea.jpg", "pixel": "750*200", "url": "https://a3.rabbitpre.com/m2/FqcsnQ67eqD", "size": 110, "remarks": "变更截止日期及增加到达站", "createDate": "2022-08-09 17:39:10", "createId": 16, "status": 3, "auditStat": 9, "agentId": 4, "agentName": "中信通", "advertiserName": "汕头市达阳广告传媒有限公司", "title": "行程信息推广", "industryType": "10", "companyCode": "91440500MA55GKKJ5T", "advertisersBrand": "行程信息推广" }, { "id": 9371, "billUuid": "e35f905a35874ad0a7f04443bb4e0b59", "regionNo": 2, "fileName": "2.微信推广素材2.jpg", "fileType": "jpg", "resourcesUrl": "/deliverywx/2022/05/30/ee45d00379a84369a375c6e73ee37875.jpg", "pixel": "690*400", "url": "https://a3.rabbitpre.com/m2/FqcsnQ67eqD", "size": 163, "remarks": "变更截止日期及增加到达站", "createDate": "2022-08-09 17:39:10", "createId": 16, "status": 3, "auditStat": 9, "agentId": 4, "agentName": "中信通", "advertiserName": "汕头市达阳广告传媒有限公司", "title": "行程信息推广", "industryType": "10", "companyCode": "91440500MA55GKKJ5T", "advertisersBrand": "行程信息推广" } ], "mAuditStat": 9, "mAuditStatString": "变更二审通过", "mStatus": 3, "mStatusString": "审核通过", "title": "行程信息推广", "industryType": "10", "industry": "其他", "companyCode": "91440500MA55GKKJ5T", "advertisersBrand": "行程信息推广", "url": "https://a3.rabbitpre.com/m2/FqcsnQ67eqD", "sumclick": 0, "sumview": 0, "ratio": 0 }, { "uuid": "b849bc3e6372433f91b99a68bbafa1b8", "agentId": 4, "agentName": "中信通", "advertiserName": "铁鹿科技(广州)有限公司", "createDate": "2022-08-09 15:49:56", "createId": 16, "materials": [ { "id": 9368, "billUuid": "b849bc3e6372433f91b99a68bbafa1b8", "regionNo": 1, "fileName": "顶部图.jpg", "fileType": "jpg", "resourcesUrl": "/deliverywx/2022/08/04/93c8a9bb2f834ea48fa90cd319400f48.jpg", "pixel": "750*200", "url": "http://xuanchuan.laiyongxing.com:81", "size": 58, "remarks": "已更改截图", "createDate": "2022-08-09 15:49:56", "createId": 16, "status": 3, "auditStat": 4, "agentId": 4, "agentName": "中信通", "advertiserName": "铁鹿科技(广州)有限公司", "title": "赖永兴酒", "industryType": "5", "companyCode": "91440101MA9Y9GMG8L", "advertisersBrand": "赖永兴酒" }, { "id": 9369, "billUuid": "b849bc3e6372433f91b99a68bbafa1b8", "regionNo": 2, "fileName": "中部图.jpg", "fileType": "jpg", "resourcesUrl": "/deliverywx/2022/08/04/aec0d6b6e9084b3c95e01ebe395ca6f4.jpg", "pixel": "690*400", "url": "http://xuanchuan.laiyongxing.com:81", "size": 93, "remarks": "已更改截图", "createDate": "2022-08-09 15:49:56", "createId": 16, "status": 3, "auditStat": 4, "agentId": 4, "agentName": "中信通", "advertiserName": "铁鹿科技(广州)有限公司", "title": "赖永兴酒", "industryType": "5", "companyCode": "91440101MA9Y9GMG8L", "advertisersBrand": "赖永兴酒" } ], "mAuditStat": 4, "mAuditStatString": "二审通过", "mStatus": 3, "mStatusString": "审核通过", "title": "赖永兴酒", "industryType": "5", "industry": "酒", "companyCode": "91440101MA9Y9GMG8L", "advertisersBrand": "赖永兴酒", "url": "http://xuanchuan.laiyongxing.com:81", "sumclick": 0, "sumview": 0, "ratio": 0 } ], "pageNum": 0, "pageSize": 0, "size": 2, "startRow": 1, "endRow": 2, "pages": 0, "prePage": 0, "nextPage": 0, "isFirstPage": false, "isLastPage": true, "hasPreviousPage": false, "hasNextPage": false, "navigatePages": 8, "navigatepageNums": [], "navigateFirstPage": 0, "navigateLastPage": 0 } }
我现在要取json数据中advertiserName值
public static void main(String[] args) { String str = "{n" + " "code": 200,n" + " "message": "SUCCESS",n" + " "data": {n" + " "total": 2,n" + " "list": [n" + " {n" + " "id": 3421,n" + " "uuid": "e35f905a35874ad0a7f04443bb4e0b59",n" + " "orderNo": "2022-GD-W-126",n" + " "agentId": 4,n" + " "agentName": "中信通",n" + " "advertiserName": "汕头市达阳广告传媒有限公司",n" + " "status": 0,n" + " "auditStat": 1,n" + " "createDate": "2022-08-09 17:39:10",n" + " "createId": 16,n" + " "materials": [n" + " {n" + " "id": 9370,n" + " "billUuid": "e35f905a35874ad0a7f04443bb4e0b59",n" + " "regionNo": 1,n" + " "fileName": "1.微信推广素材1.jpg",n" + " "fileType": "jpg",n" + " "resourcesUrl": n" + " "/deliverywx/2022/05/30/a84841854502430ab51b41233728a6ea.jpg",n" + " "pixel": "750*200",n" + " "url": "https://a3.rabbitpre.com/m2/FqcsnQ67eqD",n" + " "size": 110,n" + " "remarks": "变更截止日期及增加到达站",n" + " "createDate": "2022-08-09 17:39:10",n" + " "createId": 16,n" + " "status": 3,n" + " "auditStat": 9,n" + " "agentId": 4,n" + " "agentName": "中信通",n" + " "advertiserName": "汕头市达阳广告传媒有限公司",n" + " "title": "行程信息推广",n" + " "industryType": "10",n" + " "companyCode": "91440500MA55GKKJ5T",n" + " "advertisersBrand": "行程信息推广"n" + " },n" + " {n" + " "id": 9371,n" + " "billUuid": "e35f905a35874ad0a7f04443bb4e0b59",n" + " "regionNo": 2,n" + " "fileName": "2.微信推广素材2.jpg",n" + " "fileType": "jpg",n" + " "resourcesUrl": n" + " "/deliverywx/2022/05/30/ee45d00379a84369a375c6e73ee37875.jpg",n" + " "pixel": "690*400",n" + " "url": "https://a3.rabbitpre.com/m2/FqcsnQ67eqD",n" + " "size": 163,n" + " "remarks": "变更截止日期及增加到达站",n" + " "createDate": "2022-08-09 17:39:10",n" + " "createId": 16,n" + " "status": 3,n" + " "auditStat": 9,n" + " "agentId": 4,n" + " "agentName": "中信通",n" + " "advertiserName": "汕头市达阳广告传媒有限公司",n" + " "title": "行程信息推广",n" + " "industryType": "10",n" + " "companyCode": "91440500MA55GKKJ5T",n" + " "advertisersBrand": "行程信息推广"n" + " }n" + " ],n" + " "mAuditStat": 9,n" + " "mAuditStatString": "变更二审通过",n" + " "mStatus": 3,n" + " "mStatusString": "审核通过",n" + " "title": "行程信息推广",n" + " "industryType": "10",n" + " "industry": "其他",n" + " "companyCode": "91440500MA55GKKJ5T",n" + " "advertisersBrand": "行程信息推广",n" + " "url": "https://a3.rabbitpre.com/m2/FqcsnQ67eqD",n" + " "sumclick": 0,n" + " "sumview": 0,n" + " "ratio": 0n" + " },n" + " {n" + " "uuid": "b849bc3e6372433f91b99a68bbafa1b8",n" + " "agentId": 4,n" + " "agentName": "中信通",n" + " "advertiserName": "铁鹿科技(广州)有限公司",n" + " "createDate": "2022-08-09 15:49:56",n" + " "createId": 16,n" + " "materials": [n" + " {n" + " "id": 9368,n" + " "billUuid": "b849bc3e6372433f91b99a68bbafa1b8",n" + " "regionNo": 1,n" + " "fileName": "顶部图.jpg",n" + " "fileType": "jpg",n" + " "resourcesUrl": n" + " "/deliverywx/2022/08/04/93c8a9bb2f834ea48fa90cd319400f48.jpg",n" + " "pixel": "750*200",n" + " "url": "http://xuanchuan.laiyongxing.com:81",n" + " "size": 58,n" + " "remarks": "已更改截图",n" + " "createDate": "2022-08-09 15:49:56",n" + " "createId": 16,n" + " "status": 3,n" + " "auditStat": 4,n" + " "agentId": 4,n" + " "agentName": "中信通",n" + " "advertiserName": "铁鹿科技(广州)有限公司",n" + " "title": "赖永兴酒",n" + " "industryType": "5",n" + " "companyCode": "91440101MA9Y9GMG8L",n" + " "advertisersBrand": "赖永兴酒"n" + " },n" + " {n" + " "id": 9369,n" + " "billUuid": "b849bc3e6372433f91b99a68bbafa1b8",n" + " "regionNo": 2,n" + " "fileName": "中部图.jpg",n" + " "fileType": "jpg",n" + " "resourcesUrl": n" + " "/deliverywx/2022/08/04/aec0d6b6e9084b3c95e01ebe395ca6f4.jpg",n" + " "pixel": "690*400",n" + " "url": "http://xuanchuan.laiyongxing.com:81",n" + " "size": 93,n" + " "remarks": "已更改截图",n" + " "createDate": "2022-08-09 15:49:56",n" + " "createId": 16,n" + " "status": 3,n" + " "auditStat": 4,n" + " "agentId": 4,n" + " "agentName": "中信通",n" + " "advertiserName": "铁鹿科技(广州)有限公司",n" + " "title": "赖永兴酒",n" + " "industryType": "5",n" + " "companyCode": "91440101MA9Y9GMG8L",n" + " "advertisersBrand": "赖永兴酒"n" + " }n" + " ],n" + " "mAuditStat": 4,n" + " "mAuditStatString": "二审通过",n" + " "mStatus": 3,n" + " "mStatusString": "审核通过",n" + " "title": "赖永兴酒",n" + " "industryType": "5",n" + " "industry": "酒",n" + " "companyCode": "91440101MA9Y9GMG8L",n" + " "advertisersBrand": "赖永兴酒",n" + " "url": "http://xuanchuan.laiyongxing.com:81",n" + " "sumclick": 0,n" + " "sumview": 0,n" + " "ratio": 0n" + " }n" + " ],n" + " "pageNum": 0,n" + " "pageSize": 0,n" + " "size": 2,n" + " "startRow": 1,n" + " "endRow": 2,n" + " "pages": 0,n" + " "prePage": 0,n" + " "nextPage": 0,n" + " "isFirstPage": false,n" + " "isLastPage": true,n" + " "hasPreviousPage": false,n" + " "hasNextPage": false,n" + " "navigatePages": 8,n" + " "navigatepageNums": [],n" + " "navigateFirstPage": 0,n" + " "navigateLastPage": 0n" + " }n" + "}"; JSONObject object1 = JSON.parseObject(str); String reStr2 = String.valueOf(object1.get("data")); JSONObject object2 = JSON.parseObject(reStr2); JSONArray array = object2.getJSONArray("list"); for (int i = 0; i < array.size(); i++) { JSONObject jsonObject2 = array.getJSONObject(i); String advertiserName = String.valueOf(jsonObject2.get("advertiserName")); System.out.println("advertiserName: "+advertiserName); } }
输出
advertiserName: 汕头市达阳广告传媒有限公司 advertiserName: 铁鹿科技(广州)有限公司