【发布时间】:2020-09-24 08:55:43
【问题描述】:
我有一个返回 JSON 数据结构的 ruby 文件
class BankDetails
DETAILS = [
{
currencyCode: 'usd',
currencyName: 'United States Dollar',
iban: 'CH13 0070 0130 0089 9043 3',
bankName: 'Zürcher Kantonalbank',
bic: 'ZKBKCHZZ80A',
},
{
currencyCode: 'chf',
currencyName: 'Swiss Franc',
iban: 'CH60 0070 0110 0067 2153 4',
bankName: 'Zürcher Kantonalbank',
bic: 'ZKBKCHZZ80A',
},
{
currencyCode: 'eur',
currencyName: 'Euro',
iban: 'CH88 0070 0130 0089 9044 1',
bankName: 'Zürcher Kantonalbank',
bic: 'ZKBKCHZZ80A',
},
{
currencyCode: 'zar',
currencyName: 'South African Rand',
iban: 'CH60 0070 0110 0067 2153 4',
bankName: 'Zürcher Kantonalbank',
bic: 'ZKBKCHZZ80A',
},
{
currencyCode: 'nad',
currencyName: 'Namibian Dollar',
iban: 'CH60 0070 0110 0067 2153 4',
bankName: 'Zürcher Kantonalbank',
bic: 'ZKBKCHZZ80A',
},
].freeze
def self.fetch_bank_details
DETAILS
end
end
现在我想将相同的 JSON 放入一个新的 yml 文件中,并以与从 ruby 文件中调用 BankDetails 类获得的相同结构获取数据。 yml 文件的具体结构应该是什么?
【问题讨论】:
-
首先,您可以简单地在 YAML 文件中使用 JSON。 JSON 是 YAML 的子集。
-
这种结构可以工作吗?
default: bank_details: - currency_code: usd currency_name: United States Dollar iban: CH13 0070 0130 0089 9043 3 bank_name: Zürcher Kantonalbank bic: ZKBKCHZZ80A - currency_code: chf currency_name: Swiss Franc iban: CH60 0070 0110 0067 2153 4 bank_name: Zürcher Kantonalbank bic: ZKBKCHZZ80A