我在 MySQL 数据库中有一个列,其中包含 json 格式值的 python 列表,如下所示:
| 列 |
|---|
| [{"name":"me","color":"red"} , {"name":"you","color":"blue"}] |
我无法使用 json_extract() 函数,因为它的格式与 json 不完全相同
我想提取新列中格式化的每个 json ,如下所示:
| 第一列 | 第二列 |
|---|---|
| {“名称”:“我”,“颜色”:“红色”} | {"name":"you","color":"blue"} |
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您应该能够在问题中包含的示例列上使用 JSON_EXTRACT:
SET @column = '[{"name":"me","color":"red"} , {"name":"you","color":"blue"}]'; SELECT JSON_EXTRACT(@column, '$[0]') AS First_column, JSON_EXTRACT(@column, '$[1]') AS Second_column;输出: