有没有办法从Java中的JSON获取特定属性的所有值?

有没有办法从Java中的JSON获取特定属性的所有值?,java,json,Java,Json,“项目”:[ { “名称”:“默认用户”, “项目”:[ { “名称”:“设置”, “项目”:[ { “名称”:“/身份服务/令牌[管理员SSO身份验证][默认用户]”, “事件”:[ { “倾听”:“测试”, “脚本”:{ “id”:“87ee6424-4b8f-444c-96d8-0c11e66e0820”, “执行官”:[ “var jsonData=JSON.parse(responseBody);\r”, “\r”, “pm.test(request.name+”200 OK“,函数(

“项目”:[ { “名称”:“默认用户”, “项目”:[ { “名称”:“设置”, “项目”:[ { “名称”:“/身份服务/令牌[管理员SSO身份验证][默认用户]”, “事件”:[ { “倾听”:“测试”, “脚本”:{ “id”:“87ee6424-4b8f-444c-96d8-0c11e66e0820”, “执行官”:[ “var jsonData=JSON.parse(responseBody);\r”, “\r”, “pm.test(request.name+”200 OK“,函数(){\r”, “pm.response.to.have.status(200);\r”, “});\r”, “\r”, “pm.collectionVariables.set(“admin\u access\u token”,jsonData.access\u token);\r”, “\r”, “如果(pm.collectionVariables.has(“SkipResponsetTimeValidation”)| | pm.collectionVariables.has(“skipContentTypeValidation”){\r”, “pm.collectionVariables.unset”(“skipResponseTimeValidation”);\r”, “pm.collectionVariables.unset”(“skipContentTypeValidation”);\r”, “console.log(“取消设置SkipResponsetTimeValidation和skipContentTypeValidation集合变量”);\r”, "}" ], “类型”:“文本/javascript” } }, { “侦听”:“预请求”, “脚本”:{ “id”:“527f6d95-6eac-46e0-b030-9e3045948344”, “执行官”:[ pm.collectionVariables.set(“bundlesUsername”apipostmantestbundles@gmail.com”;\r“, “pm.collectionVariables.set”(“skipResponseTimeValidation”);\r”, “pm.collectionVariables.set(“skipContentTypeValidation”) ], “类型”:“文本/javascript” } } ], “请求”:{ “auth”:{ “类型”:“noauth” }, “方法”:“获取”, “标题”:[ { “键”:“内容类型”, “名称”:“内容类型”, “类型”:“文本”, “值”:“应用程序/json” } ], “url”:{ “raw”:“{ssourl}}/identity service/token?grant_type=password&scope=openid+profile+email&client_id={{clientId}}}和client_secret={{clientSecret}}和username={{bundleusername}}和password={{ssoAdminPassword}”, “主持人”:[ “{{ssourl}}” ], “路径”:[ “身份证服务”, “代币” ], “查询”:[ { “密钥”:“授权类型”, “值”:“密码” }, { “关键”:“范围”, “值”:“openid+配置文件+电子邮件” }, { “密钥”:“客户端id”, 值“{clientId}” }, { “密钥”:“客户机密”, 值“{clientSecret}}” }, { “密钥”:“用户名”, 值“{bundlesUsername}}” }, { “密钥”:“密码”, 值“{ssoAdminPassword}” } ] }, “说明”:“为成功登录生成身份验证令牌” }, “答复”:[] }, { “名称”:“/roles[获取默认角色RoleId][默认用户]”, “事件”:[ { “倾听”:“测试”, “脚本”:{ “id”:“86b3d7db-85f7-474e-9c0d-cd3081bf6480”, “执行官”:[ “var jsonData=pm.response.json();\r”, “\r”, “pm.test(request.name+“响应状态为200 OK”,函数(){\r”, “pm.response.to.have.status(200);\r”, “});\r”, “\r”, “pm.test(request.name+“获取默认角色roleId”,()=>{\r”, “var jsonResponse=jsonData.find(jsonData=>jsonData.value==pm.environment.get(“defaultRole”);\r”, “\tpm.collectionVariables.set”(“defaultRoleId”,jsonResponse.id);\r”, “});\r”, “\r”, “如果(pm.collectionVariables.has(“SkipResponsetTimeValidation”)| | pm.collectionVariables.has(“skipContentTypeValidation”){\r”, “pm.collectionVariables.unset”(“skipResponseTimeValidation”);\r”, “pm.collectionVariables.unset”(“skipContentTypeValidation”);\r”, “console.log(“取消设置SkipResponsetTimeValidation和skipContentTypeValidation集合变量”);\r”, "}" ], “类型”:“文本/javascript” } }, { “侦听”:“预请求”, “脚本”:{ “id”:“fd0d704f-1b71-4220-8244-e384d8a16a42”, “执行官”:[ “pm.collectionVariables.set”(“skipResponseTimeValidation”);\r”, “pm.collectionVariables.set(“skipContentTypeValidation”) ], “类型”:“文本/javascript” } } ], “请求”:{ “方法”:“获取”, “标题”:[ { “密钥”:“身份验证”, “值”:“{admin\u access\u token}}”, “类型”:“文本” }, { “键”:“内容类型”, “值”:“应用程序/json”, “类型”:“文本” }, { “键”:“接受语言”, “值”:“en”, “类型”:“文本” } ], “url”:{ “原始”:“{url}}/roles”, “主持人”:[ “{{url}}” ], “路径”:[ “角色” ] }, “说明”:“获取默认角色Id” }, “答复”:[] }, { “名称”:“/用户[获取用户ID][默认用户]”, “事件”:[ { “倾听”:“测试”, “脚本”:{ “id”:“5ea818f4-7072-496d-8927-230ba331e5c7”, “执行官”:[ “var jsonData=pm.response.json();\r”, “\r”, “pm.test(request.name+“响应状态为200 OK”,函数(){\r”, “pm.response.to.have.status(200);\r”, “});\r”, “\r”, “pm.test(request.name+“获取默认用户用户ID”,()=>{\r”, “var jsonResponse=jsonData.find(jsonData=>jsonData.username==pm.environment.get(“SSODaultUserName”);\r”, “\tpm.collectionVariables.set”(“userId”,jsonResponse.id);\r”, “});\r”, “\r”, “如果(pm.collectionVariables.has(“SkipResponsetTimeValidation”)| | pm.collectionVariables.has(“skipContentTypeValidation”){\r”, “pm.collectionVariables.unset”(“skipResponseTimeValidation”);\r”, “pm.collectionVariables.unset”(“skipContentTypeValidation”);\r”, “console.log(“取消设置SkipResponsetTimeValidation和skipContentTypeValidation集合变量”);\r”, "}" ], “类型”:“文本/javascript” } }, { “侦听”:“预请求”, “脚本”:{ “id”:“727132f3-8e9b-4f51-8e84-c88f872f5519”, “执行官”:[ “pm.collectionVariables.set”(“skipResponseTimeValidation”);\r”, “pm.collectionVariables.set(“skipContentTypeValidation”) ], “类型”:“文本/javascript” } } ], “请求”:{ “方法”:“获取”, “标题”:[ { “密钥”:“身份验证”, “值”:“{admin\u access\u token}}”, “类型”:“文本” }, { “键”:“内容类型”, “值”:“应用程序/json”, “类型”:“文本” }, { “键”:“接受语言”, “值”:“en”, “类型”:“文本” } ], “url”:{ “原始”:“{url}}/users”, “主持人”:[ “{{url}}” ], “路径”:[ “用户” ] }, “说明”:“获取用户的用户Id” }, “答复”:[] }, { “名称”:“/角色[创建角色][默认用户]”, “事件”:[ { “侦听”:“预请求”, “脚本”:{ “id”:“585bfe92-74f7-48b7-b1cb-c5ed1e06fb03”, “执行官”:[ pm.collectionVariables.set(“randomValue”,.random(1500000));\r, “pm.collectionVariables.set”(“skipResponseTimeValidation”);\r”, “pm.collectionVariables.set(“skipContentTypeValidation”) ], “类型”:“文本/javascript” } }, { “倾听”:“测试”, “脚本”:{ “id”:“31e104ce-e7fd-4308-985c-e44a2df88ef4”, “执行官”:[ “var jsonData=pm.response.json();\r”
[["var jsonData = JSON.parse(responseBody);",
"",
"pm.test(\"Response status is 200 OK\",
 function () {",
"    pm.response.to.have.status(200);",
"});",
"",
"pm.collectionVariables.set(\"access_token\",
 jsonData.access_token);",
"",
"if (pm.collectionVariables.has(\"skipResponseTimeValidation\") || pm.collectionVariables.has(\"skipContentTypeValidation\")) {",
"    pm.collectionVariables.unset(\"skipResponseTimeValidation\");",
"    pm.collectionVariables.unset(\"skipContentTypeValidation\");",
"    console.log(\"Unset skipResponseTimeValidation and skipContentTypeValidation collection variables\");",
"}"],

["pm.collectionVariables.set(\"systemsUsername\",
 \"apipostmantestsystems@gmail.com\");\r",
"pm.collectionVariables.set(\"systemsPassword\",
 \"post123!\");\r",
"pm.collectionVariables.set(\"skipResponseTimeValidation\");\r",
"pm.collectionVariables.set(\"skipContentTypeValidation\");"],

[""],

[""],

["var jsonData = pm.response.json();\r",
"\r",
"var sysName = [\"eCl@ss\"];\r",
"\r",
"pm.test(request.name + \" 200\",
 function () {\r",
"    pm.response.to.have.status(200);\r",
"});\r",
"\r",
"pm.test(request.name + \" Verify the systems and its attributes \",
 () => {   \r",
"    flag = false;\r",
"        for (var count = 0; count < jsonData.length; count++) {\r",
"             if (sysName == jsonData[count].details[0].name ) {\r",
"                  pm.expect(jsonData[count]).to.have.property(\"code\");\r",
"                  pm.expect(jsonData[count]).to.have.property(\"systemVersion\");\r",
"                  pm.expect(jsonData[count].localizedDetails).to.have.property(\"id\");\r",
"                  pm.expect(jsonData[count].localizedDetails.language).to.have.property(\"id\");\r",
"                  pm.expect(jsonData[count].localizedDetails.language).to.have.property(\"value\");\r",
"                  pm.expect(jsonData[count].localizedDetails.language).to.have.property(\"description\");\r",
"                  pm.expect(jsonData[0].localizedDetails.language).to.have.property(\"priority\");\r",
"                  pm.expect(jsonData[0].localizedDetails).to.have.property(\"name\");\r",
"                  pm.expect(jsonData[0].details[0]).to.have.property(\"id\");\r",
"                  pm.expect(jsonData[0].details[0].language).to.have.property(\"id\");\r",
"                  pm.expect(jsonData[0].details[0].language).to.have.property(\"value\");\r",
"                  pm.expect(jsonData[0].details[0].language).to.have.property(\"description\");\r",
"                  pm.expect(jsonData[0].details[0].language).to.have.property(\"priority\");\r",
"                  pm.expect(jsonData[0].details[0]).to.have.property(\"name\");\r",
"                  pm.expect(jsonData[0]).to.have.property(\"allowMultiple\");\r",
"                  pm.collectionVariables.set(\"systemId\",
 jsonData[count].id);\r",
"        flag = true;\r",
"        break; \r",
"            }\r",
"        }\r",
"        pm.expect(flag).to.eql(true);\r",
"});"],

[""]]
var jsonData = JSON.parse(responseBody);

pm.test("Response status is 200 OK", function () {
    pm.response.to.have.status(200);
});

pm.collectionVariables.set("access_token", jsonData.access_token);

if (pm.collectionVariables.has("skipResponseTimeValidation") || pm.collectionVariables.has("skipContentTypeValidation")) {
    pm.collectionVariables.unset("skipResponseTimeValidation");
    pm.collectionVariables.unset("skipContentTypeValidation");
    console.log("Unset skipResponseTimeValidation and skipContentTypeValidation collection variables");
}
pm.collectionVariables.set("systemsUsername", "apipostmantestsystems@gmail.com");
pm.collectionVariables.set("systemsPassword", "post123!");
pm.collectionVariables.set("skipResponseTimeValidation");
pm.collectionVariables.set("skipContentTypeValidation");


var jsonData = pm.response.json();

var sysName = ["eCl@ss"];

pm.test(request.name + " 200", function () {
    pm.response.to.have.status(200);
});

pm.test(request.name + " Verify the systems and its attributes ", () => {   
    flag = false;
        for (var count = 0; count < jsonData.length; count++) {
             if (sysName == jsonData[count].details[0].name ) {
                  pm.expect(jsonData[count]).to.have.property("code");
                  pm.expect(jsonData[count]).to.have.property("systemVersion");
                  pm.expect(jsonData[count].localizedDetails).to.have.property("id");
                  pm.expect(jsonData[count].localizedDetails.language).to.have.property("id");
                  pm.expect(jsonData[count].localizedDetails.language).to.have.property("value");
                  pm.expect(jsonData[count].localizedDetails.language).to.have.property("description");
                  pm.expect(jsonData[0].localizedDetails.language).to.have.property("priority");
                  pm.expect(jsonData[0].localizedDetails).to.have.property("name");
                  pm.expect(jsonData[0].details[0]).to.have.property("id");
                  pm.expect(jsonData[0].details[0].language).to.have.property("id");
                  pm.expect(jsonData[0].details[0].language).to.have.property("value");
                  pm.expect(jsonData[0].details[0].language).to.have.property("description");
                  pm.expect(jsonData[0].details[0].language).to.have.property("priority");
                  pm.expect(jsonData[0].details[0]).to.have.property("name");
                  pm.expect(jsonData[0]).to.have.property("allowMultiple");
                  pm.collectionVariables.set("systemId", jsonData[count].id);
        flag = true;
        break; 
            }
        }
        pm.expect(flag).to.eql(true);
});