本文介绍了mysql 从数组中提取json元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过索引提取 JSON 元素,例如
I need to extract JSON element by index e.g.
SELECT JSON_EXTRACT('[{"featureId":"a","read":1,"write":1,"delete":1},{"featureId":"2","read":1,"write":0,"delete":1}]', '$[0].*');
但它只是提取了我想要提取的部分的值,如下所示:
But it just extracts the values I want extracted part to be like this:
{
"featureId": "a",
"read": 1,
"write": 1,
"delete": 1
}
推荐答案
尝试:
SELECT JSON_EXTRACT('
[
{"featureId":"a","read":1,"write":1,"delete":1},
{"featureId":"2","read":1,"write":0,"delete":1}
]
', '$[0]');
请参阅 db-fiddle.
这篇关于mysql 从数组中提取json元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!