我有以下格式的数据:
"article_body" : [
{
"article_desc" : "THURSDAY, Sept. 1, 2016 (HealthDay News) -- Dapagliflozin improves insulin sensitivity and increases lipid oxidation and plasma ketone concentration in patients with type 2 diabetes mellitus (T2DM), according to a study published online Aug. 25 in Diabetes Care. \n\n Giuseppe Daniele",
"links" : [{
"link_name" : "Full Text (subscription or payment may be required)"}
]}
],
Run Code Online (Sandbox Code Playgroud)
我想提取密钥
article_desc
Run Code Online (Sandbox Code Playgroud)
从article_body.
我在 Mysql 中的代码片段:
SELECT
JSON_EXTRACT(full_article_json, '$.article_body."article_desc"') AS description,
FROM
wc_article_full_data;
Run Code Online (Sandbox Code Playgroud)
我得到空数据,如何解析这些数据?
你的key = 'article_body'是一个数组JSON,所以你需要使用索引来获取数据。
你可以试试这个。
架构(MySQL v5.7)
CREATE TABLE wc_article_full_data(
full_article_json JSON
);
insert into wc_article_full_data values (
'{"article_body" : [
{
"article_desc" : "THURSDAY, Sept. 1, 2016 (HealthDay News) -- Dapagliflozin improves insulin sensitivity and increases lipid oxidation and plasma ketone concentration in patients with type 2 diabetes mellitus (T2DM), according to a study published online Aug. 25 in Diabetes Care. Giuseppe Daniele",
"links" : [{
"link_name" : "Full Text (subscription or payment may be required)"}
]}
]}');
Run Code Online (Sandbox Code Playgroud)
查询#1
SELECT JSON_EXTRACT(full_article_json,'$.article_body[0].article_desc') AS descriptio
FROM wc_article_full_data;
| descriptio |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| "THURSDAY, Sept. 1, 2016 (HealthDay News) -- Dapagliflozin improves insulin sensitivity and increases lipid oxidation and plasma ketone concentration in patients with type 2 diabetes mellitus (T2DM), according to a study published online Aug. 25 in Diabetes Care. Giuseppe Daniele" |
Run Code Online (Sandbox Code Playgroud)
article_desc如果你想从数组中获取所有值article_body。您可以尝试在索引中使用*。
SELECT JSON_EXTRACT(full_article_json,'$.article_body[*].article_desc') AS descriptio
FROM wc_article_full_data
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7565 次 |
| 最近记录: |