#json_object 对@j做了多层转义,导致数据入库后“前带‘\’
start transaction ;
set @j='{"Monday": {"EndTime": "18:00", "StartTime": "8:00"}, "Sunday": {"EndTime": "18:00", "StartTime": "8:00"}}';
select @j , json_set(@j,'$.Concat','[99999]');
set @g = json_object('WorkTime',json_set(@j,'$.Concat','[99999]'));
select @g;
commit ;
#直接拼装json字符串写入数据,避开多次转格式导致的‘\’
start transaction ;
set @j='{"Monday":{"StartTime":"7:00","EndTime":"20:00"},"Wednesday":{"StartTime":"7:00","EndTime":"20:00"},"Thursday ":{"StartTime":"7:00","EndTime":"20:00"},"Friday":{"StartTime":"13:00","EndTime":"18:00"},"Saturday":{"StartTime":"13:00","EndTime":"18:00"}}';
set @g=concat('{"WorkTime":', @j,'}');
UPDATE tb_userclockininfo
SET ChangeType = 123,
WorkTimeJson = @g
WHERE
loginName = 'ZR20080005';
commit ;
但是concat在拼装到程序代码中时出现错误,代码无法识别'{'是字符串内的还是字符串外的参数引用,因此避开参数;
var message = @j;#循环拼装+转为json格式,省略
var aa=@"{"+'"'+"WorkTime"+'"'+":";
var bb=@"}";
var cc= aa+message+bb