【发布时间】:2013-04-23 20:59:56
【问题描述】:
我正在尝试解析从第三方 API 接收到的一些 JSON。问题是某些 JSON 在引号内有引号,如下所示:
var json = '{"sentence": "My favorite sport is "dodgeball"." }';
我很确定浏览器将引用解释为
"My favorite sport is"
然后在以下字符上遇到语法错误。我该如何避免这种情况?
编辑:我发布了问题的简化版本,但这是给我带来麻烦的代码的实际 sn-p(问题是“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"}
【问题讨论】:
-
那个 JSON 无效。他到底是从 API 获得的?
-
我正在提取用户列表,而简短的个人简介部分有时会包含双引号。遗憾的是,该服务 (zoho.com) 没有对其进行消毒。
-
这不是“消毒”的问题;这完全是错误的。换句话说,如果你将它提供给 JSON 解析器,它只会抛出一个异常。既然你不这样做,那你在做什么呢?
-
我从第三方 API 接收到错误的 JSON,我正在尝试修复它,以便将其提供给 JSON 解析器。
-
好吧,随便。我所要求的只是确切地查看从 API 返回的内容,原始且未受影响。您发布的是一段 JavaScript 代码,几乎可以肯定这不是 Zoho 返回的内容。
标签: javascript json