0

我正在尝试解析从第三方 API 接收到的一些 JSON。问题是一些 JSON 在引号内有引号,如下所示:

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

我很确定浏览器将引用解释为

"My favorite sport is"

然后在以下字符上遇到语法错误。我该如何避免这种情况?

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

{"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"}
4

2 回答 2

2

那不是有效的 JSON,所以你不能用标准方法来做。

您要么必须像这样转义引号:"sport is \" "否则您需要编写自己的消毒剂

于 2013-04-23T21:01:57.453 回答
1

那些引号应该被转义 -

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

如果这是一项真正的服务(不是家庭作业),这将正确完成。如果是家庭作业,那就去修复服务中的那个错误。

于 2013-04-23T21:01:09.843 回答