我正在开发一个项目,需要使用 mySQL DB 以 JSON 格式存储数据。 我想以这种格式存储数据:
{
email1:{ data:"This is some data of email1", status:"registered", count:100 },
email1:{ data:"This is some data of email2", status:"unregistered", count:230 },
}
这里 email1 和 email2 是充当 key 的某人的两封电子邮件。在执行查询以这种格式存储和检索数据时,我发现电子邮件中也可以包含句点,例如: [email protected] 或 [email protected] 。
由于键中存在句点,我无法在数据库中执行 json 查询。喜欢:
SELECT JSON_EXTRACT(analytics, "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1d3933707c6533777572735d7a707c7471337e7270" rel="noreferrer noopener nofollow">[email protected]</a>") FROM EmailsData;
由于 [email protected] 中存在句点而不起作用 并给我这个错误:
Error Code: 3143. Invalid JSON path expression. The error is around character position 8.
有人可以建议我如何在查询中转义这些句点吗?如果不能,那么以 JSON 格式存储相应电子邮件的数据的最佳方式是什么?
最佳答案
您将需要使用类似于以下内容的单引号:
'$."<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="016c60792f6b696e6f41666c60686d2f626e6c" rel="noreferrer noopener nofollow">[email protected]</a>"'
请尝试一下。
关于mysql - 如何转义 mySql JSON 查询中的句点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65528699/