当前位置: 首页 > wzjs >正文

一般网站有哪几部分构成seo免费系统

一般网站有哪几部分构成,seo免费系统,迈步者seo,企业展厅 设计 公司 平安JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,MySQL 从 5.7版本开始支持JSON数据类型,并提供了丰富的JSON操作函数。本文将详细介绍JSON数据操作函数和JSON函数的应用,并通过具体示例帮助你掌握JSON的…
JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,MySQL 从 5.7+版本开始支持JSON数据类型,并提供了丰富的JSON操作函数。本文将详细介绍JSON数据操作函数和JSON函数的应用,并通过具体示例帮助你掌握JSON的高效使用方法。

1 JSON数据操作函数

MySQL提供了多种JSON处理函数,主要包括提取、修改、构建JSON等功能。

1.1 json_extract()与json_unquote()

  • json_extract(json_doc, path):从 JSON 文档中提取指定路径的值
  • json_unquote(json_val):去除 JSON 字符串的引号,返回纯文本
-- 提取JSON字段值
-- 示例数据
select json_extract('{"name": "张三", "age": 25}', '$.name') as name;
-- 输出: "张三"(带引号)
mysql> select json_extract('{"name": "张三", "age": 25}', '$.name') as name;
+----------+
| name     |
+----------+
| "张三"   |
+----------+
1 row in set (0.01 sec)mysql> -- 使用json_unquote去掉引号
select json_unquote(json_extract('{"name": "张三", "age": 25}', '$.name')) as name;
-- 输出: 张三(纯文本)
mysql> select json_unquote(json_extract('{"name": "张三", "age": 25}', '$.name')) as name;
+--------+
| name   |
+--------+
| 张三   |
+--------+
1 row in set (0.01 sec)mysql> 

1.2 json_array()与json_object()

  • json_array(val1, val2, ...):构建JSON数组
  • json_object(key1, val1, key2, val2, ...):构建JSON对象
-- 构建json数组
select json_array(1, 'mysql', true, null) as json_array;
-- 输出: [1, "mysql", true, null]
mysql> select json_array(1, 'mysql', true, null) as json_array;
+--------------------------+
| json_array               |
+--------------------------+
| [1, "mysql", true, null] |
+--------------------------+
1 row in set (0.01 sec)mysql> -- 构建json对象
select json_object('id', 1, 'name', '张三', 'is_active', true) as json_obj;
-- 输出: {"id": 1, "name": "张三", "is_active": true}
mysql> select json_object('id', 1, 'name', '张三', 'is_active', true) as json_obj;
+------------------------------------------------+
| json_obj                                       |
+------------------------------------------------+
| {"id": 1, "name": "张三", "is_active": true}   |
+------------------------------------------------+
1 row in set (0.00 sec)mysql> 

2 JSON 函数在实际开发中的应用

2.1 解析嵌套JSON字段

2.1.1 数据准备

create table user (user_id int primary key,profile_data json
);insert into user values 
(1, '{"name": "张三", "contact": {"email": "zhangsan@example.com", "phone": "13800138000"}}'),
(2, '{"name": "李四", "contact": {"email": "lisi@example.com", "phone": null}}');
commit;

2.1.2 查询嵌套字段

-- 查询所有用户的邮箱
select user_id,profile_data ->> '$.name' as name,profile_data ->> '$.contact.email' as email
from user;mysql> select ->     user_id,->     profile_data ->> '$.name' as name,->     profile_data ->> '$.contact.email' as email-> from user;
+---------+--------+----------------------+
| user_id | name   | email                |
+---------+--------+----------------------+
|       1 | 张三   | zhangsan@example.com |
|       2 | 李四   | lisi@example.com     |
+---------+--------+----------------------+
2 rows in set (0.00 sec)mysql> 

2.2 存储和查询复杂结构数据

2.2.1 数据准备

create table orders (order_id int primary key,order_info json
);insert into orders values 
(1001, '{"order_date": "2023-10-01","customer": "张三","items": [{"product_id": 101, "name": "手机", "price": 5999, "quantity": 1},{"product_id": 205, "name": "耳机", "price": 399, "quantity": 2}]
}');
commit;

2.2.2 数据查询

-- 提取第一个商品名称
select order_id,order_info ->> '$.customer' as customer,order_info -> '$.items[0].name' as first_product
from orders;mysql> select ->     order_id,->     order_info ->> '$.customer' as customer,->     order_info -> '$.items[0].name' as first_product-> from orders;
+----------+----------+---------------+
| order_id | customer | first_product |
+----------+----------+---------------+
|     1001 | 张三     | "手机"        |
+----------+----------+---------------+
1 row in set (0.01 sec)mysql> 

3 总结

场景

推荐函数

提取JSON字段

json_extract()

构建JSON

json_array(),json_object()

解析嵌套JSON

json_table()(MySQL 8.0+)

存储动态结构数据

直接使用JSON数据类型

http://www.dtcms.com/wzjs/291835.html

相关文章:

  • 档案局网站的建设网络优化软件有哪些
  • 学做ps的软件的网站seo教程优化
  • 用电脑做网站的历史在哪里找百度一下首页网址
  • 网站建设文化咨询宁波seo快速优化课程
  • wordpress漂亮轮播代码厦门seo培训
  • 青海省住房和城乡建设厅网站首页网站模板哪家好
  • wordpress 前台打不开百度关键词优化手段
  • 视频网站亏钱为什么还要继续做站长统计app软件下载2021
  • 提供盐城网站开发谷歌手机网页版入口
  • 万年历网站做广州seo优化排名推广
  • 后台管理网站建设什么推广平台好
  • 怎么看网站使用什么做的谷歌搜索引擎google
  • 如何做网站推广方法网络营销的定义
  • 搬瓦工可以长期做网站seo是什么意思seo是什么职位
  • 网站被黑能查到是谁做的吗长尾关键词是什么意思
  • wordpress关键词替换某企业网站的分析优化与推广
  • wordpress登录用户错乱昆明长尾词seo怎么优化
  • 品牌微信网站建设网页搜索关键字
  • 西安网站开发多少钱网站建设与管理
  • 专业网站建设设计seo网站推广服务
  • 赚钱的网站做任务属于免费的网络营销方式
  • 免费建筑设计素材网站搜索量用什么工具查询
  • 做政府网站运营经典广告
  • 小鼠标网站建设网络营销常见的工具
  • 智慧团建网站官网电脑版电脑突然多了windows优化大师
  • 欢迎访问中国建设银行网站个人客户简阳seo排名优化课程
  • 低价网站建设方案百度账号申诉中心
  • 备案怎么关闭网站吗关键词你们懂的
  • 做一门户网站价格免费网站友情链接
  • 网站设计uiseo专业培训