猿问

求一个JSON数据更新的问题

PHP+MYSQL

字段info为JSON类型,现在想更新ID为2里的第二个age的值,从42修改为14,前面的age等保持不变

怎么搞?


梵蒂冈之花
浏览 528回答 2
2回答

莫回无

$info = '[{"age":"12", "time":"2016-04-20"}, {"age":"42", "time":"2001-09-02"}]'; $info = json_decode($info, true); $info[1]['age'] = 14; $info = json_encode($info);

慕容森

update 表名 set info = json_set(info,"$.age","14") where id = 2; #对id为2的info键值进行修改以下代码update **表名** set info = json_set(info,"$.age","14") where id = 2;
随时随地看视频慕课网APP
我要回答