Json parsing functions in python do not support single quotes.

Source: Internet
Author: User
The json parsing function of the python standard library is used. loads is a json string that cannot be referenced using single quotes. for example, use double quotes instead, or call json before loads. dumps (a) is also acceptable. & Amp; gt; a & amp; quot; {aa: dd, dd: df} & amp; quot; & amp; gt; & amp; gt; importjson & amp; gt; bj... the json parsing function of the python standard library is used. loads is a json string that cannot be referenced using single quotes. The example is as follows:

Use double quotation marks, or call json. dumps (a) before loads.

>>> a = "{'aa':'dd','dd':'df'}">>> import json>>> b = json.loads(a)Traceback (most recent call last):  File "
 
  ", line 1, in 
  
     File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads    return _default_decoder.decode(s)  File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode    obj, end = self.raw_decode(s, idx=_w(s, 0).end())  File "/usr/lib64/python2.6/json/decoder.py", line 336, in raw_decode    obj, end = self._scanner.iterscan(s, **kw).next()  File "/usr/lib64/python2.6/json/scanner.py", line 55, in iterscan    rval, next_pos = action(m, context)  File "/usr/lib64/python2.6/json/decoder.py", line 171, in JSONObject    raise ValueError(errmsg("Expecting property name", s, end))ValueError: Expecting property name: line 1 column 1 (char 1)>>> a = '{"aa":"asdf","dd":"dfads"}  File "
   
    ", line 1    a = '{"aa":"asdf","dd":"dfads"}                                  ^SyntaxError: EOL while scanning string literal>>> a = '{"aa":"asdf","dd":"dfads"}'>>> b = json.loads(a)>>> b>>> {u'aa': u'asdf', u'dd': u'dfads'}
   
  
 

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.