@summary: --------- @param json_object: json对象或json格式的字符串 @param key: 建值 如果在多个层级目录下 可写 key1.key2 如{'key1':{'key2':3}} --------- @result: 返回对应的值,如果没有,返回''
(json_object, key)
| 1016 | |
| 1017 | |
| 1018 | def get_json_value(json_object, key): |
| 1019 | """ |
| 1020 | @summary: |
| 1021 | --------- |
| 1022 | @param json_object: json对象或json格式的字符串 |
| 1023 | @param key: 建值 如果在多个层级目录下 可写 key1.key2 如{'key1':{'key2':3}} |
| 1024 | --------- |
| 1025 | @result: 返回对应的值,如果没有,返回'' |
| 1026 | """ |
| 1027 | current_key = "" |
| 1028 | value = "" |
| 1029 | try: |
| 1030 | json_object = ( |
| 1031 | isinstance(json_object, str) and get_json(json_object) or json_object |
| 1032 | ) |
| 1033 | |
| 1034 | current_key = key.split(".")[0] |
| 1035 | value = json_object[current_key] |
| 1036 | |
| 1037 | key = key[key.find(".") + 1 :] |
| 1038 | except Exception as e: |
| 1039 | return value |
| 1040 | |
| 1041 | if key == current_key: |
| 1042 | return value |
| 1043 | else: |
| 1044 | return get_json_value(value, key) |
| 1045 | |
| 1046 | |
| 1047 | def get_all_keys(datas, depth=None, current_depth=0): |