<p>我在python3中也遇到了同样的问题。
以下是我的方法:</p>
<p><strong>方法1</strong>:按照其他人的建议,在字符串前面添加<code>r'...'</code>,将字符串转换为原始字符串。如下所示。在</p>
<pre><code>>>> json.loads('''{"source":"\u003ca href=\"http:\/\/twitter.com\" \u003eTwitter \u003c\/a\u003e"}''')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 21 (char 20)
>>> json.loads(r'''{"source":"\u003ca href=\"http:\/\/twitter.com\" \u003eTwitter \u003c\/a\u003e"}''')
{'source': '<a href="http://twitter.com" >Twitter </a>'}
</code></pre>
<p><strong>方法2</strong>:应该将字符串作为<code>bytes</code>对象读入,因为字符串包含十六进制和控制字符。<code>json.loads()</code>也可以处理<code>bytes</code>对象,因为Python3.6。在</p>