MySQL 解析 json 数组(mysql在5.7开始支持json解析)

 

1.函数 JSON_EXTRACT

表数据格式:

 

 

 查询结果:

 

 

 sql 语句:

-- ----------------------------
-- Table structure for jsonarray_test
-- ----------------------------
DROP TABLE IF EXISTS `jsonarray_test`;
CREATE TABLE `jsonarray_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '名称',
UNIQUE KEY `title` (`title`),
KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of jsonarray_test
-- ----------------------------
INSERT INTO `jsonarray_test` VALUES ('1', '[{\"id\":1,\"name\":\"张三\"},{\"id\":1,\"name\":\"李四\"},{\"id\":3,\"name\":\"王五\"}]');



SELECT id, REPLACE (
        JSON_EXTRACT (title, '$[*].name'),
        '"',
        ''
    ) AS 'name'
FROM
jsonarray_test

 

整体截图:

posted @ 2019-12-23 19:21  ElevenXiao  阅读(12458)  评论(0编辑  收藏  举报