simplejson.loads()get无效 escape:'x'
我正在学习如何使用simplejson解码JSON文件。但我遭遇了“无效逃脱”错误。
这是代码
import simplejson as json
def main():
json.loads(r'{"test":"x27"}')
if __name__ == '__main__':
main()
这是错误信息
Traceback (most recent call last):
File "hello_world.py", line 7, in <module>
main()
File "hello_world.py", line 4, in main
json.loads(r'{"test":"x27"}')
File "C:Userszhangkaipythonsimplejson__init__.py", line 307, in loads
return _default_decoder.decode(s)
File "C:Userszhangkaipythonsimplejsondecoder.py", line 335, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:Userszhangkaipythonsimplejsondecoder.py", line 351, in raw_decode
obj, end = self.scan_once(s, idx)
File "C:Userszhangkaipythonsimplejsonscanner.py", line 36, in _scan_once
return parse_object((string, idx + 1), encoding, strict, _scan_once, object_
hook)
File "C:Userszhangkaipythonsimplejsondecoder.py", line 185, in JSONObject
value, end = scan_once(s, end)
File "C:Userszhangkaipythonsimplejsonscanner.py", line 34, in _scan_once
return parse_string(string, idx + 1, encoding, strict)
File "C:Userszhangkaipythonsimplejsondecoder.py", line 114, in py_scanstr
ing
raise ValueError(errmsg(msg, s, end))
ValueError: Invalid escape: 'x': line 1 column 10 (char 10)
我认为json解析器应该识别转义。所以我想知道什么是错的,我该怎么办。
没有找到相关结果
已邀请:
3 个回复
倾坞髓
),详情请参见此处。它有一个unicode转义,
其中
是四个十六进制数字,但没有
十六进制转义。
青董据零
,
,
,
,
,
,
,
或
(其后必须跟随4个十六进制字符)。不允许
。请参阅http://json.org/上的规范
粳饶瓢部