当前位置:网站首页>MySQL fully parses json/ arrays
MySQL fully parses json/ arrays
2022-07-05 20:40:00 【1024 questions】
mysql analysis json Array
Go straight up demo
The following demo It can be copied directly to sql function
Let's analyze
mysql json The string is parsed into the corresponding field
resolvent :JSON_EXTRACT
resolvent :REPLACE
mysql analysis json Arraymysql stay 5.7 Start supporting json Parsed You can also parse arrays !
Go straight up demo SELECT Substr(col, 2, Length(col) - 2), Length(col) FROM (SELECT Json_extract(Json_extract(Json_extract(state, "$.tpl"),"$.items" ), "$[0].url") AS col FROM page ORDER BY id DESC LIMIT 100) t;
JSON_EXTRACT Can be parsed sql , tpl You are the one json Of key value
If it's an array , use $[*].url perhaps $[0].url Get all of value Or some subscript url
The following demo It can be copied directly to sql function select JSON_EXTRACT(JSON_EXTRACT(JSON_EXTRACT('{"tpl":{"items":[{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FiZ0OtkhTZoD7fOtkp55SnuLGiKu.png?imageView2/2/w/750","id":1542348252537},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FlR1VDQWEzD406NosLFrJUez4g_X.png?imageView2/2/w/750","id":1542348263477},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FhMuYkWvnoMbv8I1dlQbm1KaX5Kn.png?imageView2/2/w/750","id":1542348269599},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FlgR4IUNElPbcgjN2re_9A8jX30v.png?imageView2/2/w/750","id":1542348276124},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FpXF8ETHxU8aqriiKbsYDjnu2Xd5.png?imageView2/2/w/750","id":1542348282561},{"type":"image","config":{"expandable":true,"linkAble":true},"url":"https://fs.esf.fangdd.net/test/FkUz5m7Jd6kE2slSyreDucozc3XH.png?imageView2/2/w/750","id":1542348288150,"link":"http://www.baidu.com"}],"bottomItems":[],"title":"demo2","description":"","wxLogo":"","bodyStyleInline":{},"bg":"","bgType":"","bottomStyleInline":{},"bottomBg":"","bottomBgType":"","uuid":"aaef8dfe-256a-4559-aec9-95d1fcdcf830","activeItemsName":"items","activeImgType":"","authInfo":{"role_list":[{"name":"test","access_key_list":[]},{"name":" Reviewers ","access_key_list":[]}],"city_list":[],"userId":3108779,"userName":"zhangyusheng","email":"[email protected]","mobile":"123123","trueName":" Zhang Yusheng ","isEmployee":true}}}', "$.tpl"), "$.items"), "$[0].url");
Let's analyze original json by
{ "tpl":{ "items":[ { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FiZ0OtkhTZoD7fOtkp55SnuLGiKu.png?imageView2/2/w/750", "id":1542348252537 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FlR1VDQWEzD406NosLFrJUez4g_X.png?imageView2/2/w/750", "id":1542348263477 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FhMuYkWvnoMbv8I1dlQbm1KaX5Kn.png?imageView2/2/w/750", "id":1542348269599 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FlgR4IUNElPbcgjN2re_9A8jX30v.png?imageView2/2/w/750", "id":1542348276124 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FpXF8ETHxU8aqriiKbsYDjnu2Xd5.png?imageView2/2/w/750", "id":1542348282561 }, { "type":"image", "config":{ "expandable":true, "linkAble":true }, "url":"https://fs.esf.fangdd.net/test/FkUz5m7Jd6kE2slSyreDucozc3XH.png?imageView2/2/w/750", "id":1542348288150, "link":"http://www.baidu.com" } ], "bottomItems":[ ], "title":"demo2", "description":"", "wxLogo":"", "bodyStyleInline":{ }, "bg":"", "bgType":"", "bottomStyleInline":{ }, "bottomBg":"", "bottomBgType":"", "uuid":"aaef8dfe-256a-4559-aec9-95d1fcdcf830", "activeItemsName":"items", "activeImgType":"", "authInfo":{ "role_list":[ { "name":"test", "access_key_list":[ ] }, { "name":" Reviewers ", "access_key_list":[ ] } ], "city_list":[ ], "userId":3108779, "userName":"zhangyusheng", "email":"[email protected]", "mobile":"23123", "trueName":" Zhang Yusheng ", "isEmployee":true } }}
$.tpl
Is to get tpl This key key
$[0].url
Is to get [{url:1},{url:2}] Of the first object in this array url value That is to say 1
Field name :mobile , Content :{"contactName":" paragraph XX","contactJobTitle":" To be confirmed ","contactMobile":"131XXXXXXX"}.
resolvent :JSON_EXTRACTperform SQL:
Query results :
The result is quoted , Can't really use .
resolvent :REPLACEperform SQL:
Query results :
Problem solving .
sql sentence :
SELECTREPLACE (JSON_EXTRACT (mobile, '$.contactName'),'"','') AS 'contactName',REPLACE (JSON_EXTRACT (mobile, '$.contactMobile'),'"','') AS 'contactMobile',REPLACE (JSON_EXTRACT (mobile, '$.contactJobTitle'),'"','') AS 'contactJobTitle'FROMcscw_clientWHEREid = 'XXXXXXXXXXXXXXX'
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .
边栏推荐
- 信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
- Point cloud file Dat file read save
- 科普|英语不好对NPDP考试有影响吗 ?
- 死信队列入门(两个消费者,一个生产者)
- [Yugong series] go teaching course in July 2022 004 go code Notes
- CTF reverse Foundation
- 小程序代码的构成
- 王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
- Abnova DNA marker high quality control test program
- Scala basics [HelloWorld code parsing, variables and identifiers]
猜你喜欢
小程序全局配置
Practical demonstration: how can the production research team efficiently build the requirements workflow?
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
2.8、项目管理过程基础知识
全国爱眼教育大会,2022第四届北京国际青少年眼健康产业展会
Hongmeng OS' fourth learning
Classic implementation of the basic method of intelligent home of Internet of things
Abbkine trakine F-actin Staining Kit (green fluorescence) scheme
Abnova maxpab mouse derived polyclonal antibody solution
鸿蒙os第四次学习
随机推荐
Abnova DNA marker high quality control test program
ProSci LAG3抗体的化学性质和应用说明
Duchefa丨P1001植物琼脂中英文说明书
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
Duchefa MS medium contains vitamin instructions
Abnova丨CRISPR SpCas9 多克隆抗体方案
2022 Beijing eye health products exhibition, eye care products exhibition, China eye Expo held in November
Applet global configuration
CTF逆向基础
如何形成规范的接口文档
Norgen AAV extractant box instructions (including features)
中国管理科学研究院凝聚行业专家,傅强荣获智库专家“十佳青年”称号
Make Jar, Not War
[record of question brushing] 1 Sum of two numbers
Use of form text box (II) input filtering (synthetic event)
【UE4】UnrealInsight获取真机性能测试报告
AI automatically generates annotation documents from code
Sort and projection
Duchefa s0188 Chinese and English instructions of spectinomycin hydrochloride pentahydrate
Is the securities account given by the school of Finance and business safe? Can I open an account?