I have the following string that I am trying to convert into a dictionary in python:
data = "{'ABC - 1 check NEW_PAGE': 'red', 'CDE - 2 checks SQL_DATA': 'black', 'The temporary file generated contains the following errors : ['20235874;172426;admin_AB_34;S_DEB;100;FC_SUCCESS_F']': 'red'}"
What I am trying to use in python is the following lines of code:
data = data.replace("'", "\"")
data = json.loads(data)
I get the following error:
json.decoder.JSONDecodeError: Expecting ':' delimiter: line 1 column 187 (char 186)
Could someone help me with a solution? It would really be appreciated
You're escaping '
, but it is not necessary when is between "
:
data = data.replace("'", "\"")
data = json.loads(data)
But you'll probably hit another issue with the end of the data string "'The temporary file generated contains the following errors: ['20235874;172426;admin_AB_34;S_DEB;100;FC_SUCCESS_F']'; 'red'"
. Which seems to be invalid json string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.