json字符串解码遇到无效的转义 [英] json string decoding encountering invalid escape

查看:112
本文介绍了json字符串解码遇到无效的转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用simplejson解码以下json字符串.

I am using simplejson to decode the following json string.

这是一个用Python编写的演示:

Here is a demo written in Python:

from simplejson import loads

loads("""["\s"]""")

解码器将抛出:

JSONDecodeError: Invalid \escape

如何应对?预期的输出是:

How to cope with this? The expected output is:

["\\s"]

推荐答案

"\ s"不是有效的JSON逸出字符串.

"\s" is not a valid JSON escape string.

根据 json.org ,只有以下转义符有效

According to json.org, only the following escape are valid

  • \"
  • \\
  • /
  • \ b
  • \ f
  • \ n
  • \ r
  • \ t
  • \ u 四个十六进制数字
  • \"
  • \\
  • /
  • \b
  • \f
  • \n
  • \r
  • \t
  • \u four-hex-digits

这篇关于json字符串解码遇到无效的转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆