Skip to content

Instantly share code, notes, and snippets.

@HQMIS
Created December 18, 2012 09:07
Show Gist options
  • Select an option

  • Save HQMIS/4326422 to your computer and use it in GitHub Desktop.

Select an option

Save HQMIS/4326422 to your computer and use it in GitHub Desktop.
【Python】【Library】【json】
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import json
>>> json_str = "{'json':'str'}"
>>> json.loads(json_str)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
json.loads(json_str)
File "E:\Python27\lib\json\__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "E:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "E:\Python27\lib\json\decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 1 (char 1)
>>> json_str = '{"json":"str"}'
>>> json.loads(json_str)
{u'json': u'str'}
>>> json_str = '{"json":"str\str"}'
>>> json.loads(json_str)
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
json.loads(json_str)
File "E:\Python27\lib\json\__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "E:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "E:\Python27\lib\json\decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Invalid \escape: line 1 column 12 (char 12)
>>> json_str = '{"json":"str\\str"}'
>>> json.loads(json_str)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
json.loads(json_str)
File "E:\Python27\lib\json\__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "E:\Python27\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "E:\Python27\lib\json\decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Invalid \escape: line 1 column 12 (char 12)
>>> json_str = '{"json":"str\\\\str"}'
>>> json.loads(json_str)
{u'json': u'str\\str'}
>>>
@HQMIS

HQMIS commented Dec 18, 2012

Copy link
Copy Markdown
Author

关于ValueError: Expecting property name: http://bugs.python.org/issue5067

@HQMIS

HQMIS commented Dec 18, 2012

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment