我有這個(gè) JSON 文件,里面有幾個(gè)鍵:{ "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盡管該元素基于給定存在,但它會(huì)返回key。
盡管項(xiàng)目存在于文件中,但基于密鑰從 JSON 文件獲取項(xiàng)目失敗
哆啦的時(shí)光機(jī)
2024-01-04 16:22:36