W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
以下完整長(zhǎng)度示例指定YAML的構(gòu)造,其中包括符號(hào)和各種表示,這些表示在以JSON格式轉(zhuǎn)換或處理它們時(shí)將非常有用。 這些屬性在JSON文檔中也稱為鍵名。 這些符號(hào)是出于安全目的而創(chuàng)建的。
上述YAML格式表示具有各種其他屬性的默認(rèn)值,適配器和主機(jī)的各種屬性。 YAML還會(huì)記錄生成的每個(gè)文件,這些文件會(huì)保留生成的錯(cuò)誤消息的跟蹤。 在以JSON格式轉(zhuǎn)換指定的YAML文件時(shí),得到所需的輸出,如下所述 -
defaults: &defaults
adapter: postgres
host: localhost
development:
database: myapp_development
<<: *defaults
test:
database: myapp_test
<<: *defaults
下面將YAML轉(zhuǎn)換為JSON格式并檢查輸出。
{
"defaults": {
"adapter": "postgres",
"host": "localhost"
},
"development": {
"database": "myapp_development",
"adapter": "postgres",
"host": "localhost"
},
"test": {
"database": "myapp_test",
"adapter": "postgres",
"host": "localhost"
}
}
前綴為<<:*的默認(rèn)鍵包含在必需時(shí),無需重復(fù)編寫相同的代碼段。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: