尝试使用rest-assured来获得以下json响应中关键字“orgId”的总次数。
直接使用response.path("orgId") ; null
时正在返回
json响应如下所述。有什么可以解决这个问题?
{
"code": 200,
"message": "Successfull",
"access_token": "2342",
"data": [
{
"orgId": 131,
"orgName": "Publish",
"orgUrl": "http://globalthoughtz.com/",
"orgDesc": "The much-loved premium Moto X series is now called Moto Z, and has a whole new identity based around snap-on accessories. ",
"orgLogo": "http://miriadna.com/desctopwalls/images/max/Red-autumn-morning.jpg",
"assignWhen": null,
"shareUrl": null,
"shareTitle": "Share title updated",
"shareDesc": "A few things have changed in terms of branding and segmentation, which shows that sticking to your roots doesn't mean stagnating. hello",
"shareImage": "https://s-media-cache-ak0.pinimg.com/236x/fb/5d/91/fb5d91d632ff34e4ae04393926f92bde.jpg",
"checkTwtStatus": true
},
{
"orgId": 573,
"orgName": "Marketing",
"orgUrl": "http://123.com/ ",
"orgDesc": "werf",
"orgLogo": "",
"assignWhen": null,
"shareUrl": null,
"shareTitle": null,
"shareDesc": null,
"shareImage": null,
"checkTwtStatus": null
},
{
"orgId": 574,
"orgName": "Customer Support",
"orgUrl": "1.com",
"orgDesc": "test team",
"orgLogo": "",
"assignWhen": null,
"shareUrl": null,
"shareTitle": "",
"shareDesc": "",
"shareImage": "",
"checkTwtStatus": null
},
{
"orgId": 575,
"orgName": "Insurance",
"orgUrl": "facebook.com",
"orgDesc": "Added From IE",
"orgLogo": "",
"assignWhen": null,
"shareUrl": null,
"shareTitle": "",
"shareDesc": "",
"shareImage": "",
"checkTwtStatus": null
},
{
"orgId": 637,
"orgName": "Sales",
"orgUrl": "http://uae.souq.com/ae-en/apple/smart-watches-511/",
"orgDesc": "CHECK CSRF ",
"orgLogo": "http://leads.plus/wp-content/uploads/2016/03/sales-teamwork.jpg",
"assignWhen": null,
"shareUrl": null,
"shareTitle": "",
"shareDesc": "",
"shareImage": "",
"checkTwtStatus": null
}
]
}
答案 0 :(得分:0)
path(String, String...)
允许您使用groovy来解析响应体,因此您可以轻松编写response.path("data.orgId.size")
并获取data.orgId
数组的实际大小