读取json文件 Read json file key: 读取一级嵌套路径信息 Key2: 读取key二级嵌套路径信息 .... 最多支持五级嵌套路径, 默认读取所有json文件内的信息 return: 成功返回json文件字典数据, 失败返回False Key: Read the first-level nested path information Key2: rea
(self, path, key=None, Key2=None, Key3=None, Key4=None, Key5=None)
| 73 | return False |
| 74 | |
| 75 | def ReadJsonFile(self, path, key=None, Key2=None, Key3=None, Key4=None, Key5=None) -> str or bool: |
| 76 | """ |
| 77 | 读取json文件 |
| 78 | Read json file |
| 79 | |
| 80 | key: 读取一级嵌套路径信息 |
| 81 | Key2: 读取key二级嵌套路径信息 |
| 82 | .... 最多支持五级嵌套路径, 默认读取所有json文件内的信息 |
| 83 | return: 成功返回json文件字典数据, 失败返回False |
| 84 | |
| 85 | |
| 86 | Key: Read the first-level nested path information |
| 87 | Key2: read the second-level nested path information of key |
| 88 | ... supports up to five nested paths, and reads the information in all json files by default |
| 89 | return: json file data is returned successfully, and False is returned if it fails |
| 90 | """ |
| 91 | |
| 92 | try: |
| 93 | ResultData = self.ReadFile(path) |
| 94 | ResultData = json.loads(ResultData) |
| 95 | if key and Key2 and Key3 and Key4 and Key5: |
| 96 | ResultData = ResultData[key][Key2][Key3][Key4][Key5] |
| 97 | elif key and Key2 and Key3 and Key4: |
| 98 | ResultData = ResultData[key][Key2][Key3][Key4] |
| 99 | elif key and Key2 and Key3: |
| 100 | ResultData = ResultData[key][Key2][Key3] |
| 101 | elif key and Key2: |
| 102 | ResultData = ResultData[key][Key2] |
| 103 | elif key: |
| 104 | ResultData = ResultData[key] |
| 105 | return ResultData |
| 106 | except Exception as e: |
| 107 | WriteReadFile.Custom_Write_logger(self,"",f"{os.getcwd()}/AiBotRunLOG/{time.strftime(r'%Y-%m-%d',time.localtime(time.time()))}/","SysModeError.log",False,"error",f"{traceback.format_exc()}") |
| 108 | return False |
| 109 | |
| 110 | |
| 111 |
no test coverage detected