我打电话给与money.js一起使用的货币汇率api来转换汇率,这不是问题。我想从返回的json数据中选择特定比率。
{
"base": "EUR",
"date": "2016-03-31",
"rates": {
"AUD": 1.4807,
"BGN": 1.9558,
"BRL": 4.1174,
"CAD": 1.4738,
"CHF": 1.0931,
"CNY": 7.3514,
"CZK": 27.051,
"DKK": 7.4512,
"GBP": 0.79155,
"HKD": 8.8282,
"HRK": 7.5255,
"HUF": 314.12,
"IDR": 15024.84,
"ILS": 4.295,
"INR": 75.4298,
"JPY": 127.9,
"KRW": 1294.88,
"MXN": 19.5903,
"MYR": 4.4078,
"NOK": 9.4145,
"NZD": 1.6411,
"PHP": 52.284,
"PLN": 4.2576,
"RON": 4.4718,
"RUB": 76.3051,
"SEK": 9.2253,
"SGD": 1.5304,
"THB": 40.018,
"TRY": 3.2118,
"USD": 1.1385,
"ZAR": 16.7866
}
}
我只是想知道例如我是否要从中提取ZAR汇率。我该怎么做
最佳答案
var res = {
"base": "EUR",
"date": "2016-03-31",
"rates": {
"AUD": 1.4807,
"BGN": 1.9558,
"BRL": 4.1174,
"CAD": 1.4738,
"CHF": 1.0931,
"CNY": 7.3514,
"CZK": 27.051,
"DKK": 7.4512,
"GBP": 0.79155,
"HKD": 8.8282,
"HRK": 7.5255,
"HUF": 314.12,
"IDR": 15024.84,
"ILS": 4.295,
"INR": 75.4298,
"JPY": 127.9,
"KRW": 1294.88,
"MXN": 19.5903,
"MYR": 4.4078,
"NOK": 9.4145,
"NZD": 1.6411,
"PHP": 52.284,
"PLN": 4.2576,
"RON": 4.4718,
"RUB": 76.3051,
"SEK": 9.2253,
"SGD": 1.5304,
"THB": 40.018,
"TRY": 3.2118,
"USD": 1.1385,
"ZAR": 16.7866
}
}
那么您可以这样做:
res.rates.ZAR;