在mysql5.8中用json_extract函数解析json

2021/12/1 19:11:26

本文主要是介绍在mysql5.8中用json_extract函数解析json,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

背景:某个字段的数据中是JSON,需要提取其中的卡号部分,如:

{"objType":"WARE","orderId":6771254073665082371,"values":["D3252","",""]}

需要提取其中的:D3252

 

示例如下:

select json_extract(x,'$.values[0]') 卡号
from
(
select '{"objType":"WARE","orderId":6771254073665082371,"values":["M2352","",""]}' x
union all
select '{"objType":"WARE","orderId":6771254073665082371,"values":["W3423","",""]}' x
union all
select '{"objType":"WARE","orderId":6771254073665082371,"values":["D3252","",""]}' x
) t

 返回:

卡号
"M2352"
"W3423"
"D3252"

 

参考:https://blog.csdn.net/lkforce/article/details/102940249

 



这篇关于在mysql5.8中用json_extract函数解析json的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程