我在字符串 groupsjasontext 中有以下 Json 值,我想使用 JsonConverter.ParseJson 解析 id、members.value、roles.value。我该怎么做?我尝试通过消息框显示 id 字段,但出现错误“类型不匹配”
Set JsonData = JsonConverter.ParseJson(groupsjasontext)
tempName = JsonData("id")(0)
MsgBox (tempName)
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:ListResponse"
],
"totalResults": 3,
"startIndex": 1,
"itemsPerPage": 3,
"Resources": [
{
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:Group",
"urn:sap:params:scim:schemas:extension:sac:2.0:group-custom-parameters"
],
"id": "d3094970-ce7e-4794-b9e2-f84817b7c820",
"meta": {
"resourceType": "Group",
"created": "2024-05-21T17:53:06.808Z",
"lastModified": "2024-05-21T17:53:06.808Z",
"location": "/api/v1/scim2/Groups/d3094970-ce7e-4794-b9e2-f84817b7c820"
},
"displayName": "AHI_VW_ALL_REGION",
"urn:sap:params:scim:schemas:extension:sac:2.0:group-custom-parameters": {
"description": "View Mode ALL REGION"
}
},
{
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:Group",
"urn:sap:params:scim:schemas:extension:sac:2.0:group-roles",
"urn:sap:params:scim:schemas:extension:sac:2.0:group-custom-parameters"
],
"id": "bef561ee-5a1e-420e-a1e\n4-4f624c96af6e",
"meta": {
"resourceType": "Group",
"created": "2024-07-25T14:17:53.215Z",
"lastModified": "2024-08-01T14:31:29.632Z",
"location": "/api/v1/scim2/Groups/bef561ee-5a1e-420e-a1e4-4f624c96af6e"
},
"displayName": "TEAM_TEST",
"members": [
{
"value": "f27dcbb9-df9a-46b2-b23a-3b35d5a8bdff",
"type": "User",
"display": "Test_FirstName1 TEST_Familyname1",
"$ref": "/api/v1/scim2/Users/f27dcbb9-df9a-46b2-b23a-3b35d5a8bdff"
}
],
"urn:sap:params:scim:schemas:extension:sac:2.0:group-roles": {
"roles": [
{
"value": "PROFILE:t.4:VIEW_USER",
"display": "VIEW_USER"
}
]
},
"urn:sap:params:scim:schemas:extension:sac:2.0:group-custom-parameters": {
"description": "Team Test"
}
},
{
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:Group",
"urn:sap:params:scim:schemas:extension:sac:2.0:group-custom-parameters"
],
"id": "1edd9227-c8de-486e-93f6-69396524c792",
"meta": {
"resourceType": "Group",
"created": "2024-05-21T17:51:49.808Z",
"lastModified": "2024-05-21T17:53:06.121Z",
"location": "/api/v1/scim2/Groups/1edd9227-c8de-486e-93f6-69396524c792"
},
"displayName": "AHI_VW_EURAM\n",
"urn:sap:params:scim:schemas:extension:sac:2.0:group-custom-parameters": {
"description": "View mode EURAM"
}
}
]
}
使用 JSonParser,可以从示例 JSON 字符串中提取所需的值,如下所示;
键
id
与单个值相关联,而不是对象或数组,因此应该
我发现在每个步骤中单独访问 JSON 对象的不同部分要容易得多。这有助于避免大多数问题以及不同对象(字典和集合)之间的混淆。我一直使用这个参考资料,事实证明它有很大帮助。
因此,根据该建议并使用链接参考,我提出了下面的测试代码来展示如何访问 JSON 结构的不同部分并在适当的时候执行循环。