YAML 鏄 "YAML Ain't a Markup Language"锛圷AML 涓嶆槸涓绉嶆爣璁拌瑷锛夌殑閫掑綊缂╁啓銆傚湪寮鍙戠殑杩欑璇█鏃讹紝YAML 鐨勬剰鎬濆叾瀹炴槸锛"Yet Another Markup Language"锛堜粛鏄竴绉嶆爣璁拌瑷锛夈

快三开奖73期—官方网址22270.COMYAML 鐨勮娉曞拰鍏朵粬楂樼骇璇█绫讳技锛屽苟涓斿彲浠ョ畝鍗曡〃杈炬竻鍗曘佹暎鍒楄〃锛屾爣閲忕瓑鏁版嵁褰㈡併傚畠浣跨敤绌虹櫧绗﹀彿缂╄繘鍜屽ぇ閲忎緷璧栧瑙傜殑鐗硅壊锛岀壒鍒傚悎鐢ㄦ潵琛ㄨ揪鎴栫紪杈戞暟鎹粨鏋勩佸悇绉嶉厤缃枃浠躲佸惧嵃璋冭瘯鍐呭銆佹枃浠跺ぇ绾诧紙渚嬪锛氳澶氱數瀛愰偖浠舵爣棰樻牸寮忓拰YAML闈炲父鎺ヨ繎锛夈

YAML 鐨勯厤缃枃浠跺悗缂涓 .yml锛屽锛runoob.yml

鍩烘湰璇硶

  • 澶у皬鍐欐晱鎰
  • 浣跨敤缂╄繘琛ㄧず灞傜骇鍏崇郴
  • 缂╄繘涓嶅厑璁镐娇鐢╰ab锛屽彧鍏佽绌烘牸
  • 缂╄繘鐨勭┖鏍兼暟涓嶉噸瑕侊紝鍙鐩稿悓灞傜骇鐨勫厓绱犲乏瀵归綈鍗冲彲
  • '#'琛ㄧず娉ㄩ噴

鏁版嵁绫诲瀷

YAML 鏀寔浠ヤ笅鍑犵鏁版嵁绫诲瀷锛

  • 瀵硅薄锛氶敭鍊煎鐨勯泦鍚堬紝鍙堢О涓烘槧灏勶紙mapping锛/ 鍝堝笇锛坔ashes锛 / 瀛楀吀锛坉ictionary锛
  • 鏁扮粍锛氫竴缁勬寜娆″簭鎺掑垪鐨勫硷紝鍙堢О涓哄簭鍒楋紙sequence锛 / 鍒楄〃锛坙ist锛
  • 绾噺锛坰calars锛夛細鍗曚釜鐨勩佷笉鍙啀鍒嗙殑鍊

YAML 瀵硅薄

瀵硅薄閿煎浣跨敤鍐掑彿缁撴瀯琛ㄧず key: value锛屽啋鍙峰悗闈㈣鍔犱竴涓┖鏍笺

涔熷彲浠ヤ娇鐢 key:{key1: value1, key2: value2, ...}

杩樺彲浠ヤ娇鐢ㄧ缉杩涜〃绀哄眰绾у叧绯伙紱

key: 
    child-key: value
    child-key2: value2

杈冧负澶嶆潅鐨勫璞℃牸寮忥紝鍙互浣跨敤闂彿鍔犱竴涓┖鏍间唬琛ㄤ竴涓鏉傜殑 key锛岄厤鍚堜竴涓啋鍙峰姞涓涓┖鏍间唬琛ㄤ竴涓 value锛

?  
    - complexkey1
    - complexkey2
:
    - complexvalue1
    - complexvalue2

鎰忔濆嵆瀵硅薄鐨勫睘鎬ф槸涓涓暟缁 [complexkey1,complexkey2]锛屽搴旂殑鍊间篃鏄竴涓暟缁 [complexvalue1,complexvalue2]

YAML 鏁扮粍

- 寮澶寸殑琛岃〃绀烘瀯鎴愪竴涓暟缁勶細

- A
- B
- C

YAML 鏀寔澶氱淮鏁扮粍锛屽彲浠ヤ娇鐢ㄨ鍐呰〃绀猴細

key: [value1, value2, ...]

鏁版嵁缁撴瀯鐨勫瓙鎴愬憳鏄竴涓暟缁勶紝鍒欏彲浠ュ湪璇ラ」涓嬮潰缂╄繘涓涓┖鏍笺

-
 - A
 - B
 - C

涓涓浉瀵瑰鏉傜殑渚嬪瓙锛

companies:
    -
        id: 1
        name: company1
        price: 200W
    -
        id: 2
        name: company2
        price: 500W

鎰忔濇槸 companies 灞炴ф槸涓涓暟缁勶紝姣忎竴涓暟缁勫厓绱犲張鏄敱 id銆乶ame銆乸rice 涓変釜灞炴ф瀯鎴愩

鏁扮粍涔熷彲浠ヤ娇鐢ㄦ祦寮(flow)鐨勬柟寮忚〃绀猴細

companies: [{id: 1,name: company1,price: 200W},{id: 2,name: company2,price: 500W}]

澶嶅悎缁撴瀯

鏁扮粍鍜屽璞″彲浠ユ瀯鎴愬鍚堢粨鏋勶紝渚嬶細

languages:
  - Ruby
  - Perl
  - Python 
websites:
  YAML: yaml.org 
  Ruby: ruby-lang.org 
  Python: python.org 
  Perl: use.perl.org

杞崲涓 json 涓猴細

{ 
  languages: [ 'Ruby', 'Perl', 'Python'],
  websites: {
    YAML: 'yaml.org',
    Ruby: 'ruby-lang.org',
    Python: 'python.org',
    Perl: 'use.perl.org' 
  } 
}

绾噺

绾噺鏄渶鍩烘湰鐨勶紝涓嶅彲鍐嶅垎鐨勫硷紝鍖呮嫭锛

  • 瀛楃涓
  • 甯冨皵鍊
  • 鏁存暟
  • 娴偣鏁
  • Null
  • 鏃堕棿
  • 鏃ユ湡

浣跨敤涓涓緥瀛愭潵蹇熶簡瑙g函閲忕殑鍩烘湰浣跨敤锛

boolean: 
    - TRUE  #true,True閮藉彲浠
    - FALSE  #false锛孎alse閮藉彲浠
float:
    - 3.14
    - 6.8523015e+5  #鍙互浣跨敤绉戝璁℃暟娉
int:
    - 123
    - 0b1010_0111_0100_1010_1110    #浜岃繘鍒惰〃绀
null:
    nodeName: 'node'
    parent: ~  #浣跨敤~琛ㄧずnull
string:
    - 鍝堝搱
    - 'Hello world'  #鍙互浣跨敤鍙屽紩鍙锋垨鑰呭崟寮曞彿鍖呰9鐗规畩瀛楃
    - newline
      newline2    #瀛楃涓插彲浠ユ媶鎴愬琛岋紝姣忎竴琛屼細琚浆鍖栨垚涓涓┖鏍
date:
    - 2018-02-17    #鏃ユ湡蹇呴』浣跨敤ISO 8601鏍煎紡锛屽嵆yyyy-MM-dd
datetime: 
    -  2018-02-17T15:02:31+08:00    #鏃堕棿浣跨敤ISO 8601鏍煎紡锛屾椂闂村拰鏃ユ湡涔嬮棿浣跨敤T杩炴帴锛屾渶鍚庝娇鐢+浠h〃鏃跺尯

寮曠敤

& 閿氱偣鍜< span class="marked">* 鍒悕锛屽彲浠ョ敤鏉ュ紩鐢:

defaults: &defaults
  adapter:  postgres
  host:     localhost

development:
  database: myapp_development
  <<: *defaults

test:
  database: myapp_test
  <<: *defaults

鐩稿綋浜:

defaults:
  adapter:  postgres
  host:     localhost

development:
  database: myapp_development
  adapter:  postgres
  host:     localhost

test:
  database: myapp_test
  adapter:  postgres
  host:     localhost

& 鐢ㄦ潵寤虹珛閿氱偣锛坉efaults锛夛紝<< 琛ㄧず鍚堝苟鍒板綋鍓嶆暟鎹紝*快三开奖73期—官方网址22270.COM鐢ㄦ潵寮曠敤閿氱偣銆

涓嬮潰鏄彟涓涓緥瀛:

- &showell Steve 
- Clark 
- Brian 
- Oren 
- *showell 

杞负 JavaScript 浠g爜濡備笅:

[ 'Steve', 'Clark', 'Brian', 'Oren', 'Steve' ]

鍙傝冨湴鍧锛

  • http://www.ruanyifeng.com/blog/2016/07/yaml.html
  • http://www.jianshu.com/p/97222440cd08
  • http://daihainidewo.github.io/blog/yaml%E6%95%99%E7%A8%8B/