需求说明
:
今天看了json_object函数的使用,在此记录下使用过程
操作过程
:
1.使用json_object函数将一个键值对列表转换成json对象
mysql> select json_object('names','David'); #将一个键值对转换成json对象 +------------------------------+ | json_object('names','David') | +------------------------------+ | {"names": "David"} | +------------------------------+ 1 row in set (0.00 sec) mysql> select json_object('names','David','adress','Beijing'); #将两个键值对转换成json对象 +-------------------------------------------------+ | json_object('names','David','adress','Beijing') | +-------------------------------------------------+ | {"names": "David", "adress": "Beijing"} | +-------------------------------------------------+ 1 row in set (0.00 sec) mysql> select json_object('names','David','adress','Beijing','Tel',13245323345); +-------------------------------------------------------------------+ | json_object('names','David','adress','Beijing','Tel',13245323345) | +-------------------------------------------------------------------+ | {"Tel": 13245323345, "names": "David", "adress": "Beijing"} | +-------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> select json_object('names','David','adress','Beijing','Tel'); #json_object中的参数如果是奇数个也会报错 ERROR 1582 (42000): Incorre