gpt4 book ai didi

MYSQL JSON_SET 添加反斜杠

转载 作者:行者123 更新时间:2023-11-29 02:40:04 28 4
gpt4 key购买 nike

我想更新数据库中的JSON数组

我有这个数组:

Array
(
[id] => 34
[var1] => val1
[var2] => val2
[var3] => val3
)

我需要通过 id 更新 json

查询样本:

JOSN_SET(`json_arr`,'$."34"','{"id":"34","var1":"val1","var2":"val2","var3":"val3"}')

预期结果:

{"34":{"id":"34","var1":"val1","var2":"val2","var3":"val3"}}

结果:

{"34":"{\"id\":\"34\",\"var1\":\"val1\",\"var2\":\"val2\",\"var3\":\"val3\"}"}

感谢您的帮助。

最佳答案

你应该把它转换成 JSON,比如:

JOSN_SET(`json_arr`,'$."34"',CAST('{"id":"34","var1":"val1","var2":"val2","var3":"val3"}' AS JSON))

关于MYSQL JSON_SET 添加反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54615116/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com