Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL JSON_搜索-不使用双引号_Mysql_Json - Fatal编程技术网

MySQL JSON_搜索-不使用双引号

MySQL JSON_搜索-不使用双引号,mysql,json,Mysql,Json,我在用户详细信息中有如下json数据: "[{"value":"sachin","label":"What's your "first" name?"},{"value":"test@example.com","label":"What's your email?"},{"value":"+911234567890","label":"What's your "phone" number?"},{"value":"xyz","label":"What's your city?"},{"value

我在用户详细信息中有如下json数据:

"[{"value":"sachin","label":"What's your "first" name?"},{"value":"test@example.com","label":"What's your email?"},{"value":"+911234567890","label":"What's your "phone" number?"},{"value":"xyz","label":"What's your city?"},{"value":"abc","label":"What's your address?"}]"
为此,我尝试了下面的查询,但它给出了错误。只有当我的数据包含双引号(“)时才会发生错误。我如何才能使其工作

SELECT CASE WHEN json_search(user_details, 'one', '%name%', null, '$[*].label')
IS NOT NULL THEN 'name'
WHEN json_search(user_details, 'one', '%email%', null, '$[*].label')
IS NOT NULL THEN 'email'
WHEN json_search(user_details, 'one', '%phone number%', null, '$[*].label') IS NOT NULL THEN 'phone'
ELSE 'id' END type,
CASE WHEN json_search(user_details, 'one', '%name%', null, '$[*].label')
IS NOT NULL THEN
json_unquote(json_extract(user_details, concat(json_unquote(replace(json_search(user_details, 'one', '%name%', null,
'$[*].label'),'.label', '')),'.value')))
WHEN json_search(user_details, 'one', '%email%', null, '$[*].label') IS NOT NULL THEN
json_unquote(json_extract(user_details, concat(json_unquote(replace(json_search(user_details, 'one', '%email%', null,
'$[*].label'),'.label', '')),'.value')))
WHEN json_search(user_details, 'one', '%phone number%', null, '$[*].label') IS NOT NULL THEN
json_unquote(json_extract(user_details,concat(json_unquote(replace(json_search(user_details, 'one', '%phone%', null,
'$[*].label'),'.label', '')),'.value')))ELSE user_id END value FROM json_user;
尝试:

mysql>SET@`user\u details`:='[
“>{”value:“sachin”,“label:“您的名字是什么?”,
“>{”值“:”test@example.com,“标签”:“你的电子邮件是什么?”},
“>{”value:“+911234567890”,“label:“你的电话号码是多少?”},
“>{”value:“xyz”,“label:“你的城市是什么?”},
“>{”value:“abc”,“label:“你的地址是什么?”}
'> ]';
查询正常,0行受影响(0.00秒)
mysql>选择JSON_VALID(@`user_details`);
+-----------------------------+
|JSON_有效(@`user_details`)|
+-----------------------------+
|                           1 |
+-----------------------------+
一行一组(0.00秒)
mysql>选择
->JSON_UNQUOTE(
->JSON_摘录(
->@`user\u details`,
->JSON_UNQUOTE(
->替换(
->JSON_搜索(
->@`user\u details`,
->"一",,
->“%phone%”,
->空,
->“$[*].label”
->         ),
->“.label”,
->“.价值”
->       )
->     )
->   )
->)“电话”;
+---------------+
|电话|
+---------------+
| +911234567890 |
+---------------+
一行一组(0.00秒)