12

我有一个带有 JSON 列的 MySQL 表,名为sent. 列中的条目具有如下信息:

{
 "data": {
  "12":"1920293"
 }
}

我正在尝试使用 mysql 查询:

select sent->"$.data.12" from mytable

但我得到一个例外:

Invalid JSON path expression. The error is around character position 9.

知道如何提取信息吗?该查询适用于非数字子字段。

4

1 回答 1

15

@Ibrahim, You have an error in your code. If you use number (or spaced words) as key in a JSON data type in MySQL, you'll need to double-quote it.

Therefore, the correct MySQL statement in your case is:

select sent->'$.data."12"' FROM mytable;

Thanks, @JeffreyKilelo

于 2018-03-29T15:06:27.820 回答