如果你不能upgrate MySQL来5.7.8或海格。 它可以使用下面的选择:如果在客户键不存在
13 is the number of letters in the locate string ["customerId":]
或创建功能类似下面
SET @a='{"z":"\\"customerId\\"","customerId":41,"a":1,"b2":2}';
SELECT IF(LOCATE('"customerId":',@a)>0,1*substring(@a,LOCATE('"customerId":',@a)+13),NULL);
的选择返回null。这是比较有用的即时
DELIMITER //
CREATE FUNCTION json_extract_int (jstring TEXT,jkey CHAR(20))
RETURNS INT(11)
BEGIN
SET jkey = CONCAT('"',jkey,'":');
RETURN IF(LOCATE(jkey,jstring)>0,1*substring(jstring,LOCATE(jkey,jstring)+LENGTH(jkey)),NULL);
END//
DELIMITER ;
很容易使用
SELECT json_extract_int(@a,'customerId');
+-----------------------------------+
| json_extract_int(@a,'customerId') |
+-----------------------------------+
| 41 |
+-----------------------------------+
或在您的情况
SELECT json_extract_int(juniferResponse,'customerId');