在JSON中解析双引号

编程入门 行业动态 更新时间:2024-10-20 20:45:09
本文介绍了在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, 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中解析双引号

本文发布于:2023-05-29 23:10:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/355096.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双引号   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!