【发布时间】:2021-03-01 23:14:49
【问题描述】:
我有以下字符串,当我尝试将其转换为 JSON 时,如果给我一个错误
const banner =
" { "banners": [ { "startDate": "02/26/2021", "endDate": "12/25/2021","content": "Important changes have been made to the Visit google to review the updated document. <a href="https://www.google11.com" > Google11 </a>" } ] }"
Href 出错,这是我用来转换的代码
const obj = JSON.parse( banner ? banner.replace(stripTag('div'), '') : banner );
【问题讨论】:
-
您在
banner声明中混淆了双引号。目前是语法错误 -
你的代码毫无意义。当
banner是falsy你要使用它吗?当它是truthy时,您想以对我来说没有意义的方式对其进行字符串操作。即使使用div字符串,stripTag还能做什么? -
修复您的
banner声明,然后将其添加到JSON.parse。错误是什么? -
请检查我是否为我的字符串添加了图像
标签: javascript json angular