简体   繁体   English

如何修复模式描述中的“字符串中的错误转义序列”

[英]How to fix "Bad escape sequence in string" in schema description

I have use GTM to tag the schema variables.我使用 GTM 来标记模式变量。

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Product",
  "name": "{{Product-name}}",
  "description": "{{Product-description}}",
  "category": "{{Product-category}}",
  "image": "{{Product-image}}",
  "sku": "{{Product-reference}}",
  "offers": {
    "@type": "Offer",
    "url": "{{Page Path}}",
    "Price": "{{Product-price-with-dot}}",
    "priceCurrency": "[EUR]",
    "itemCondition": "https://schema.org/NewCondition",
    "availability": "{{Product-stock}}",
    "seller": {
      "@type": "Corporation",
      "name": "Magic4media"
    }
 }
}
</script>

All seems OK except for the variable value "Description" of some products whose description contains special characters.除了某些描述包含特殊字符的产品的变量值“Description”外,一切似乎都正常。 The original text is converted with more and more special caracteres... and return "Bad escape sequence in string".原始文本被越来越多的特殊字符转换...并返回“Bad escape sequence in string”。

Product-description variable set up产品描述变量设置

Original text description:原文说明:

id="pPdtDesc">Sac  shopping en coton avec anses longues. 140 gr/m². Produit sous une norme certifiée pour l'utilisation de substances nocives dans le textile.

Product description with "Bad escape sequence in string" result结果为“字符串中的转义序列错误”的产品描述

How can I fix all any possible problems with special characters?我怎样才能解决所有可能出现的特殊字符问题?

The answers was:答案是:

 function(){ var string = {{Product-description}}; return string.replace(/[^a-zA-Z0-9]/g, ''); }

        "@type": "Question",
            "name": "What is Cooper Kupp\'s major?",
            "acceptedAnswer": {
                "@type": "Answer",
                "text": "Cooper graduated from Eastern Washington University, majoring in Economics."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM