javascript - 格式化 JSON 字符串

标签 javascript json

我有这个 JSON 格式的字符串:

"message": "<?= __('I agree to the <a>Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"

我想做的是给这个表单的字符串添加一个链接

 "message": "<?= __('I agree to the <a href="%1">Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"

但是当我这样做时,出现以下错误:

SyntaxError: Unexpected token h in JSON

如何以正确的方式将链接添加到标签?

最佳答案

您必须像这样转义字符串中的双引号:

 "message": "<?= __('I agree to the <a href=\"%1\">Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"

关于javascript - 格式化 JSON 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55827463/

相关文章:

json - WSO2 ESB 是否支持 JSON 格式的 REST 到 REST?

javascript - 如何将全日历事件限制为只有一天?

php - 在 &lt;script&gt; 标签中使用 PHP?

sql - 如何在 SQL 中将 json 属性从一个记录值移至新记录值

c# - 将 JSON 字符串粘贴到 Visual Studio 中

javascript - 更新 SAPUI5/OpenUI5 中的 JSON 模型

javascript - 您可以通过 python 或 javascript 使用机器人自动化从页面检索重定向 URL 吗?

javascript - 有没有办法抓取网站并在每个页面上获取 JavaScript 变量?

javascript - 本地网络上的 Mobile Phonegap 应用程序

javascript - 尝试/捕捉 Jasmine