【发布时间】:2019-11-25 06:47:11
【问题描述】:
我需要阅读下面的 json 响应
我正在搜索一个特殊文件夹的 ID。 我知道深度级别,我希望在哪里找到文件夹,因为我知道整个路径。 我需要取回文件夹的 ID。
我所知道的是我正在寻找的文件夹的整个路径,例如 /Core/UI/Folder1/Subfolder2 所以我需要 subfolder2 的 ID。
我尝试了几个循环,但由于深入搜索而失败。 当然,我可以编写一些手动级别的深度代码,但这听起来不是我认为的正确方式。
示例 JSON
{
"folders": [
{
"rank": 1,
"name": "Core",
"id": 390,
"testCount": 0,
"totalTestCount": 0,
"testRepositoryPath": "",
"folders": [
{
"rank": 1,
"name": "UI",
"id": 391,
"testCount": 0,
"totalTestCount": 0,
"testRepositoryPath": "/Core",
"folders": [
{
"rank": 1,
"name": "Folder1",
"id": 392,
"testCount": 0,
"totalTestCount": 0,
"testRepositoryPath": "/Core/UI",
"folders": [
{
"rank": 1,
"name": "Subfolder2",
"id": 393,
"testCount": 0,
"totalTestCount": 0,
"testRepositoryPath": "/Core/UI/Folder1",
"folders": []
}
]
}
]
}
]
}
],
"allTestsCount": 791,
"allOrphanTestsCount": 791
}
【问题讨论】:
-
是基于“name”还是“testRepositoryPath”?
-
name 和 testRepositoryPath 的组合将匹配整个路径
-
您想要的路径与您的 JSON 不匹配。请解决您的问题,并确保您从您拥有的东西中准确地确定您想要的东西。告诉我们输入和期望的输出。
标签: json python-3.x for-loop