3

我想更新数据库中的 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\"}"}

谢谢您的帮助。

4

1 回答 1

5

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

JOSN_SET(`json_arr`,'$."34"',CAST('{"id":"34","var1":"val1","var2":"val2","var3":"val3"}' AS JSON))
于 2019-07-12T04:34:29.473 回答