我试图从这种货币转换中获取价值,但我不太确定该怎么做:
<script
type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'>
</script>
<script>
$.get('http://free.currencyconverterapi.com/api/v5/convert?q=EUR_USD&compact=y',
function(theValue) {
var conversion = (theValue);
console.log(conversion);
});
</script>
如果你在控制台中查看,你可以看到:
{EUR_USD: {…}}EUR_USD: val: 1.178548
...我需要在页面上显示val,以便在页面上看到1.178548
答案 0 :(得分:3)
您可以通过theValue.EUR_USD.val
和const {EUR_USD: {val: converEs6}} = theValue;
var theValue = {"EUR_USD":{"val":1.178693}}
var conversion = theValue.EUR_USD.val;
console.log(conversion);
const {EUR_USD: {val: convertEs6Style}} = theValue;
console.log(convertEs6Style)
答案 1 :(得分:1)
试试这个:
$.get('https://free.currencyconverterapi.com/api/v5/convert?q=EUR_USD&compact=y',
function(theValue) {
var conversion = theValue;
console.log(conversion.EUR_USD.val);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
答案 2 :(得分:0)
尝试console.log(conversion.EUR_USD.val);