Today a friend gives a demand:
Come to
{' IsOK ': 1, ' isrunning ': None, ' IsError ': none}
How to convert into a dictionary
Well, the first thing to see is that JSON transformation is simple:
Import JSON
a = "{' IsOK ': 1, ' isrunning ': None, ' IsError ': none}"
print Json.loads (a)
Anyway out of the results, also reported wrong, check for two hours of Baidu, did not understand.
Finally, copy the code directly from the Web, OK, run successfully, but put my a variable fill in, no, no error; Start by comparing two variables, always think of Python double quotes single quotes can be used casually, meaning unchanged; Finally, Baidu has a standard format for knowing JSON: requirements must be You can only use double quotes as a key or a boundary symbol for a value, you cannot use single quotes, and "keys" must use a border character (double quotes)
after the change, OK.
#-*-coding:utf-8-*-
Import json
a = ' {IsOK ': 1, ' isrunning ': ' None ', ' isError ': ' None '} '
B = json.loads (a)
Perhaps other languages such as PHP,JS can recognize the nonstandard JSON format, but not python;
Question: How does python turn into a dict such as a variable like a? The premise is a large amount of data .....
The above Python processing JSON string into a dictionary is a simple implementation of the small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.