当前位置:网站首页>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 .
边栏推荐
- 19 Mongoose模块化
- Graph embedding learning notes
- 重上吹麻滩——段芝堂创始人翟立冬游记
- 解析创客教育的知识迁移和分享精神
- National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
- Applet global configuration
- CVPR 2022 | common 3D damage and data enhancement
- 2.8、项目管理过程基础知识
- Classic implementation method of Hongmeng system controlling LED
- Point cloud file Dat file read save
猜你喜欢
随机推荐
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
Propping of resources
Chemical properties and application instructions of prosci Lag3 antibody
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
3.3、项目评估
How to form standard interface documents
Typhoon is coming! How to prevent typhoons on construction sites!
Make Jar, Not War
Abnova DNA marker high quality control test program
model方法
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
Scala basics [HelloWorld code parsing, variables and identifiers]
挖财商学院给的证券账户安全吗?可以开户吗?
July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing
Applet page navigation
Oracle tablespace management
Frequent MySQL operations cause table locking problems
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
台风来袭!建筑工地该如何防范台风!