快去|

Mozziemy

园龄:1年6个月粉丝:0关注:0

Yaml与Json的对比

YAML 格式:

server:  # 服务器配置
  port: 8043  # 端口号为 8043
spring:  # Spring 配置
  datasource:  # 数据源配置
    url: jdbc:mysql://localhost:3306/hbs?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&failOverReadOnly=false  # 数据库连接URL
    username: root  # 数据库用户名
    password: 123456  # 数据库密码
    driver-class-name: com.mysql.cj.jdbc.Driver  # 数据库驱动类名
  cloud:  # Spring Cloud 配置
    gateway:  # 网关配置
      routes:  # 路由配置列表开始
        - id: patient  # 第一个路由的ID
          uri: lb://wsm-patient  # 路由到 wsm-patient 服务的URI,采用负载均衡
          predicates:  # 路由的断言配置开始
            - Path=/wsm-patient/**  # 匹配路径为 /wsm-patient/**
          filters:  # 路由的过滤器配置开始
            - StripPrefix=1  # 移除请求的第一个路径段
        - id: setl  # 第二个路由的ID
          uri: lb://wsm-setl  # 路由到 wsm-setl 服务的URI,采用负载均衡
          predicates:  # 路由的断言配置开始
            - Path=/wsm-setl/**  # 匹配路径为 /wsm-setl/**
          filters:  # 路由的过滤器配置开始
            - StripPrefix=1  # 移除请求的第一个路径段
    sentinel:  # Sentinel 配置
      transport:  # Sentinel 传输配置
        dashboard: localhost:8080  # Sentinel 控制台地址
    nacos:  # Nacos 配置
      discovery:  # 服务发现配置
        server-addr: localhost:8848  # Nacos 服务器地址
  application:  # 应用程序配置
    name: wsm-setl  # 应用程序名称为 wsm-setl

JSON 格式:

{
  "server": {
    "port": 8043
  },
  "spring": {
    "datasource": {
      "url": "jdbc:mysql://localhost:3306/hbs?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&failOverReadOnly=false",
      "username": "root",
      "password": "123456",
      "driver-class-name": "com.mysql.cj.jdbc.Driver"
    },
    "cloud": {
      "gateway": {
        "routes": [
          {
            "id": "patient",
            "uri": "lb://wsm-patient",
            "predicates": [
              {
                "Path": "/wsm-patient/**"
              }
            ],
            "filters": [
              {
                "StripPrefix": 1
              }
            ]
          },
          {
            "id": "setl",
            "uri": "lb://wsm-setl",
            "predicates": [
              {
                "Path": "/wsm-setl/**"
              }
            ],
            "filters": [
              {
                "StripPrefix": 1
              }
            ]
          }
        ]
      },
      "sentinel": {
        "transport": {
          "dashboard": "localhost:8080"
        }
      },
      "nacos": {
        "discovery": {
          "server-addr": "localhost:8848"
        }
      }
    },
    "application": {
      "name": "wsm-setl"
    }
  }
}

对比:

  1. 语法

    • YAML 使用缩进和空格来表示层级关系,用-表示数组项,更加简洁易读。
    • JSON 使用大括号 {} 和方括号 [] 来表示对象和数组,语法相对繁琐一些。
  2. 可读性

    • YAML 通常比 JSON 更易读,因为它的语法更接近自然语言。
    • JSON 的语法相对更加严格,可能会显得更加冗长。
  3. 支持的数据类型

    • JSON 支持的数据类型更加丰富,包括字符串、数字、布尔值、数组、对象等。
    • YAML 也支持这些数据类型,同时还支持更多的数据结构,如日期、多行字符串等。
  4. 扩展性

    • JSON 在大多数编程语言中都有良好的支持,易于处理和解析。
    • YAML 通常需要使用专门的库来解析,有些语言的支持可能不如 JSON 那么广

本文作者:Mozziemy

本文链接:https://www.cnblogs.com/mozziemy/p/18036410

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Mozziemy  阅读(106)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起