首页 > 解决方案 > 如何从字符串中替换“并形成有效的Json

问题描述

我有一个带有 &Quot; 的 json 字符串。代替双引号,并且json文本中也有引号。如何替换这些&Quot; 双引号仅与键和值相关联,而不是在值内部,即 json 文本。

这是输入:

"description": "First: "Thank you"  always receive a very thorough examination and feel confident with my care"

and OutPut should be :  
"description": "First: "Thank you"  always receive a very thorough examination and feel confident with my care"

如果更换所有的 &Quot; 它没有生成有效的 json

引号即 &Quot; 周围谢谢你应该保留。

我从 html 页面的脚本标记中获取这个 json 字符串,并且我使用 Java 和 Xpath 从脚本标记中获取内容,它带有编码为 &Quot 的双引号。这就是我获取字符串的方式

{"@type": "Review",
     "reviewRating": {
       "@type": "Rating",
       "ratingValue": "5",
       "bestRating": "5",
       "worstRating": "1"
     },
     "description": "First: "Thank you"  always receive a very thorough examination and feel confident with my care",
     "author": {
       "@type": "Person",
       "name": "Anonymous"
     }
   }

I just want to replace the &Quot value inside the text with any value apart from double quotes ,I don't have control over the source html here 

标签: jsonescapingdouble-quotes

解决方案


推荐阅读