The following is a simple implementation of converting a json string into a dictionary in Python. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at a friend's demand today:
Lailai
{'Isok': 1, 'isrunning': None, 'iserror': None}
How to convert to dictionary
Well, the json conversion is very simple. start:
Import jsona = "{'isok': 1, 'isrunning': None, 'iserror': None}" print json. loads ()
I got an error when I got the result. I checked baidu for two hours and didn't understand it.
Finally, directly copy the code on the Internet, OK, and run successfully. but I entered the variable. no, an error is returned. start to compare the differences between the two variables, I always thought that the double quotation marks in Python can be used at will, without changing the meaning. finally, Baidu knows the standard format of json: double quotation marks must be used only as the boundary symbol of the key or value, but not single quotation marks, and the "key" must use a boundary character (double quotation marks)
After the change, OK.
#-*-Coding: UTF-8-*-import jsona = '{"isOK": 1, "isRunning": "None", "isError ": "None"} 'B = json. loads (a) print B ["isOK"]
Other languages such as php and js can recognize non-standard json formats, but Python does not;
Q: How does python convert a variable like a to dict? The premise is that the data volume is large .....
The simple implementation of the above Python processing json strings into dictionaries is all the content shared by the editor. I hope to give you a reference, and I hope you can also support the script.