我想更新数据库中的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\"}"}
感谢您的帮助。
答案 0 :(得分:0)
您应将其投射为JSON,例如:
JOSN_SET(`json_arr`,'$."34"',CAST('{"id":"34","var1":"val1","var2":"val2","var3":"val3"}' AS JSON))