求助:无法从MySQL找到JSON_CONTAINS!

在MySQL中,我使用PHP的json_encode将数据存储在“jsonValue”字段中:

{"product_category":[[{"category":["28"]},{"product":["16","22","64"]}]]}

通过PHP,我希望通过编写以下查询来获取数据:

SELECT * FROM `dbTable` 
WHERE JSON_CONTAINS(jsonValues, '"category":["28"]');

但是,它还是报错:

3141 - Invalid JSON text in argument 2 to function json_contains: "The document root must not follow by other values." at position 10.

It returns the row after writing the below codes:

SELECT * FROM `dbTable` WHERE JSON_CONTAINS(jsonValues, '{"category":["28"]}', '$.product_category');

Have you tried adding the curly brackets around your search term, as the mysql doc does?

SELECT * FROM `dbTable` WHERE JSON_CONTAINS(jsonValues, '{"category":["28"]}');

If None of the above method works for you then try below code it should work.

SELECT * FROMdbTableWHERE JSON_CONTAINS(jsonValues, '{"product_category": [[{"category": ["28"]}]]}');