json 由于转义双引号导致加载失败
json load fails because of escape double quots
test ='{"desc": "{\"OS\":\"N\",\"DR\":\"N\",\"SNAPSHOT\":\"N\",\"SERVICENAME\":\" MariaDB \"}"}'
test2 = json.loads(test)
json.decoder.JSONDecodeError:需要“,”分隔符:第 1 行第 13 列(字符 12)
我怎样才能摆脱这个地狱?
可能的解决方案如下:
test ='{"desc": "{\"OS\":\"N\",\"DR\":\"N\",\"SNAPSHOT\":\"N\",\"SERVICENAME\":\" MariaDB \"}"}'
test2 = test.replace('"{', '{').replace('}"', '}')
test2 = eval(test2)
print(test2)
print(type(test2))
版画
{'desc': {'OS': 'N', 'DR': 'N', 'SNAPSHOT': 'N', 'SERVICENAME': ' MariaDB '}}
<class 'dict'>
test ='{"desc": "{\"OS\":\"N\",\"DR\":\"N\",\"SNAPSHOT\":\"N\",\"SERVICENAME\":\" MariaDB \"}"}'
test2 = json.loads(test)
json.decoder.JSONDecodeError:需要“,”分隔符:第 1 行第 13 列(字符 12)
我怎样才能摆脱这个地狱?
可能的解决方案如下:
test ='{"desc": "{\"OS\":\"N\",\"DR\":\"N\",\"SNAPSHOT\":\"N\",\"SERVICENAME\":\" MariaDB \"}"}'
test2 = test.replace('"{', '{').replace('}"', '}')
test2 = eval(test2)
print(test2)
print(type(test2))
版画
{'desc': {'OS': 'N', 'DR': 'N', 'SNAPSHOT': 'N', 'SERVICENAME': ' MariaDB '}}
<class 'dict'>