我打电话给货币汇率api与money.js一起使用以转换汇率,这不是问题所在。我想从返回的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汇率。我怎么能这样做
答案 0 :(得分:2)
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;
答案 1 :(得分:0)
var exchange_rate = {
"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
}
}
var ratelist = exchange_rate["rates"];
console.log(ratelist["ZAR"]);