我需要在某些子元素上过滤JSON并提取父节点ID。 JSON的一部分:
[
{
"data": {
"id": "2da44298-05ec-4bb5-acce-b524ef56328c",
"attributes": {
"units": [
{
"id": "1492de82-2f36-43bf-b077-5cf54a3f38b9",
"show_name": false,
"children": [
{
"id": "a5d76efa-5b21-4874-a8a5-c9c9f8317ee6",
"contents": [
{
"id": "b96c127c-6a4f-4a29-924d-63f0ba55972a",
"link": {
"url": "#",
"target": "_blank",
"data": {
"aspect-ratio": null
}
},
"duration": null
},
{
"id": "dbb7e8fd-aa35-4acc-8ad7-1c7dcd08a6d8",
"link": {
"data": {
"id": "dbb7e8fd-aa35-4acc-8ad7-1c7dcd08a6d8",
"aspect-ratio": null
}
},
"duration": null
}
]
},
{
"id": "8a805cd0-7447-4fac-b4fc-aaa9a2f7e649",
"contents": [
{
"id": "d64138b6-5195-48b4-a0f7-b087c5496587",
"link": {
"data": {
"id": "d64138b6-5195-48b4-a0f7-b087c5496587",
"aspect-ratio": null
}
},
"duration": null
},
{
"id": "392406b1-fa20-413b-a98a-4d1a5b201d8e",
"link": {
"url": "#",
"target": "_blank",
"data": {
"id": "423498d9-8e0f-41ef-891a-34b078862ce7",
"aspect-ratio": null
}
},
"duration": null
}
]
}
],
"contents": []
}
],
"text": []
}
},
"jsonapi": {
"version": "1.0"
}
}
]
例如,需要提取根据内容ID b96c127c-6a4f-4a29-924d-63f0ba55972
过滤的单元ID
我尝试了以下表达式:
$..data..?(@contents.data.id == 'b96c127c-6a4f-4a29-924d-63f0ba55972a')].id
$..data..?(@contents.data.id == 'b96c127c-6a4f-4a29-924d-63f0ba55972a')].children.id
$..data..?(@contents.data.id == 'b96c127c-6a4f-4a29-924d-63f0ba55972a')].unit.id
我需要这样做,因为这些ID是从不同的响应中获取的。
答案 0 :(得分:0)
您可以使用嵌套的filter operators来获取父节点,例如:
public class Player : NetworkBehaviour
{
[Command]
public void CmdSpawnDefender(GameObject defender, Vector3 position, Quaternion rotation)
{
GameObject _defender = (GameObject)Instantiate(defender, position, rotation);
NetworkServer.Spawn(_defender);
}
演示:
更多信息:JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios