首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带反斜杠和引号中断的json.loads

带反斜杠和引号中断的json.loads
EN

Stack Overflow用户
提问于 2015-03-02 22:46:38
回答 1查看 1.6K关注 0票数 0

我正在尝试对以下字符串执行json.load操作

代码语言:javascript
复制
json.loads('''{"summary": "win32k.sys in the kernel-mode drivers in Microsoft Windows Server 2003 SP2, Windows Vista SP2, Windows Server 2008 SP2 and R2 SP1, Windows 7 SP1, Windows 8, Windows 8.1, Windows Server 2012 Gold and R2, and Windows RT Gold and 8.1 allows local users to gain privileges or cause a denial of service (NULL pointer dereference) via a crafted application, aka \"Win32k Elevation of Privilege Vulnerability.\"", "update_date": "2015-02-18T22: 00: 10", "version": 1}''')

但在\",它每次都在挣扎。有没有一种简单的方法可以正确地转义这个值,以便json.loads能够理解它?

EN

回答 1

Stack Overflow用户

发布于 2015-03-02 22:50:07

使用原始字符串r

代码语言:javascript
复制
json.loads(r'''{"summary": "win32k.sys in the kernel-mode drivers in Microsoft Windows Server 2003 SP2, Windows Vista SP2, Windows Server 2008 SP2 and R2 SP1, Windows 7 SP1, Windows 8, Windows 8.1, Windows Server 2012 Gold and R2, and Windows RT Gold and 8.1 allows local users to gain privileges or cause a denial of service (NULL pointer dereference) via a crafted application, aka \"Win32k Elevation of Privilege Vulnerability.\"", "update_date": "2015-02-18T22: 00: 10", "version": 1}''')

js = json.loads(r'''{"summary": "win32k.sys in the kernel-mode drivers in Microsoft Windows Server 2003 SP2, Windows Vista SP2, Windows Server 2008 SP2 and R2 SP1, Windows 7 SP1, Windows 8, Windows 8.1, Windows Server 2012 Gold and R2, and Windows RT Gold and 8.1 allows local users to gain privileges or cause a denial of service (NULL pointer dereference) via a crafted application, aka \"Win32k Elevation of Privilege Vulnerability.\"", "update_date": "2015-02-18T22: 00: 10", "version": 1}''')
print(js)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28812579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档