【问题标题】:Invalid JSON path expression. The error is around character position 1JSON 路径表达式无效。错误在字符位置 1 附近
【发布时间】:2022-01-30 05:33:01
【问题描述】:

我有一个名为carts 的表,其结构如下:

1   crt_id Primary  bigint(20)      
2   crt_mbr_id      bigint(20)          
3   crt_session_id  varchar(128)    
4   crt_content     text    
5   crt_send_type   int(11)         
6   crt_completed   tinyint(1)          
7   created_at      timestamp           
8   updated_at      timestamp   

crt_content 的数据是这样的:

[{"id":"24","quantity":"1","price":3000,"discounted":3000,"coupon":0}]

现在我需要在crt_content 中搜索号码24

所以我尝试了这个:

SELECT JSON_UNQUOTE(JSON_EXTRACT(crt_content, '24')) as scope from carts

但这会给我这个错误:

#3143 - Invalid JSON path expression. The error is around character position 1

那么这里出了什么问题?如何在此 carts 表的 crt_content 字段中正确搜索 24id

【问题讨论】:

标签: mysql sql json


【解决方案1】:

你可以试试 LIKE 查询, SELECT * from carts WHERE crt_content LIKE '%"id":"24"%';

【讨论】:

  • 对 JSON 内容使用字符串操作是相当脆弱的。
猜你喜欢
  • 2017-06-16
  • 1970-01-01
  • 2016-03-28
  • 2016-05-17
  • 2023-03-25
  • 2020-12-15
  • 2021-03-23
  • 2014-11-20
  • 2016-12-06
相关资源
最近更新 更多