我有这个 JSON 文件,里面有几个键:
{
"button-SAVE": {
"1.0.2.1.": {
"by": "id",
"locator": "com.shs.locator:id/tvSave"
},
"1.0.0": {
"by": "xpath",
"locator": "//div/span/a"
},
"1.0.1": {
"by": "xpath1",
"locator": "//div/span"
}
},
"text-SAVE": {
"1.0.2.1.": {
"by": "id",
"locator": "com.shs.locator:id/tvSave"
},
"1.0.0": {
"by": "xpath",
"locator": "//div/span/a"
},
"1.0.1": {
"by": "xpath1",
"locator": "//div/span"
}
},
"text-HOST": {
"1.0.2.1.": {
"by": "id",
"locator": "com.shs.locator:id/etHost"
},
"1.0.2": {
"by": "id",
"locator": "/ADD"
}
},
"button-close": {
"1.0.1": {
"by": "css",
"locator": "div span"
},
"1.0.2": {
"by": "css",
"locator": "div span a"
}
}
}
button-SAVE我想返回带有 key和 version 的元素1.0.2.1。这是我尝试过的:
加载我的 JSON 文件:
with open('file.json') as f:
json = load(f)
搜索
item = json['button-SAVE'].get('1.0.2.1', None)
None尽管该元素基于给定存在,但它会返回key。
月关宝盒
相关分类