繁体   English   中英

在JSON中解析双引号

[英]Parsing Double Quotes within JSON

我试图解析从第三方API接收到的JSON。 问题是某些JSON在引号内有引号,例如:

var json = '{"sentence": "My favorite sport is "dodgeball"." }';

我很确定浏览器会将报价解释为

"My favorite sport is"

然后在以下字符上出现语法错误。 如何避免这种情况?

编辑:我发布了问题的简化版本,但这是给我带来麻烦的实际代码片段(问题是用引号引起来的“ 酷供应商 ”):

{"content":"Vana Workforce is the Cloud HR Company. We are a global provider of human capital software and service solutions specifically designed to the needs of small and medium enterprises delivered on-demand.

Developed on the industry's leading cloud platform Force.com, Vana Human Capital Management delivers one complete and integrated human capital management solution for global organizations form hire to retire including the core human resource system of record, benefits & compensation, absence management, performance and talent management, career and succession planning, workforce collaboration, and workforce analytics.

Founded in 2008, Vana Workforce has offices in Canada and the United States with customers on every continent, and was recently recognized by Gartner Research as a "Cool Vendor" for 2010.","val":"Description"}

那是无效的JSON,因此您无法使用标准方法来实现。

您要么必须避免使用这样的引号: "sport is \\" " ,否则您需要编写自己的消毒剂

这些引号应转义-

"My favorite sport is \"dodgeball\"."

如果这是一项真正的服务(不是家庭作业),则可以正确完成。 如果这是家庭作业,请修复该服务中的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM