首页 > 解决方案 > 在 MySQL 中将分号分隔的字符串转换为 JSON 数组

问题描述

我需要创建一个函数,将这些数据:“test1@test.com;test2@test.com”转换为 JSON,如字符串:“[”test1@test.com”,”test2@test.com”]”。

在 MySQL 函数中......有什么想法吗?

标签: mysqlarraysstringfunction

解决方案


SET @value := '"test1@test.com;test2@test.com"';
SELECT @value, CONCAT('"[', REPLACE(@value, ';', '", "'), ']"');
@价值 CONCAT('"[', REPLACE(@value, ';', '", "'), ']"')
“test1@test.com;test2@test.com” "["test1@test.com", "test2@test.com"]"

db<>在这里摆弄


推荐阅读