在JSON中解析双引号 [英] Parsing Double Quotes within JSON

查看:119
本文介绍了在JSON中解析双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to parse some JSON I'm receiving from a third-party API. The problem is that some of the JSON has quotes inside quotes, like this:

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

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

I'm pretty sure the browser is interpreting the quote as

"My favorite sport is"

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

and then hitting an syntax error on the following characters. How do I avoid this?

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

I posted a simplified version of the problem, but here is the actual snippet of code that is giving me trouble (the problem is "Cool Vendor" wrapped in quotes):

{"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,因此无法使用标准方法来实现.

That is not valid JSON, so you cannot do it with standard methods.

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

You either have to escape the quotes like this: "sport is \" " or else you need to write your own sanitizer

这篇关于在JSON中解析双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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