@summary: 取json对象 --------- @param json_str: json格式的字符串 --------- @result: 返回json对象
(json_str)
| 943 | |
| 944 | ################################################## |
| 945 | def get_json(json_str): |
| 946 | """ |
| 947 | @summary: 取json对象 |
| 948 | --------- |
| 949 | @param json_str: json格式的字符串 |
| 950 | --------- |
| 951 | @result: 返回json对象 |
| 952 | """ |
| 953 | |
| 954 | try: |
| 955 | return json.loads(json_str) if json_str else {} |
| 956 | except Exception as e1: |
| 957 | try: |
| 958 | json_str = json_str.strip() |
| 959 | json_str = json_str.replace("'", '"') |
| 960 | keys = get_info(json_str, "(\w+):") |
| 961 | for key in keys: |
| 962 | json_str = json_str.replace(key, '"%s"' % key) |
| 963 | |
| 964 | return json.loads(json_str) if json_str else {} |
| 965 | |
| 966 | except Exception as e2: |
| 967 | log.error( |
| 968 | """ |
| 969 | e1: %s |
| 970 | format json_str: %s |
| 971 | e2: %s |
| 972 | """ |
| 973 | % (e1, json_str, e2) |
| 974 | ) |
| 975 | |
| 976 | return {} |
| 977 | |
| 978 | |
| 979 | def jsonp2json(jsonp): |
no test coverage detected