我有这个 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。
1 回答
月关宝盒
TA贡献1772条经验 获得超5个赞
后面少了一个点'1.0.2.1'
。根据您提供的 json,执行以下操作:
item = json['button-SAVE'].get('1.0.2.1.', None)
添加回答
举报
0/150
提交
取消