Python's simple implementation of converting json strings into dictionaries

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.