拜托,我想循环访问来自 API 的这个 json 响应,当我将它记录到控制台时,我一直不确定。
{
"results": {
"AF": {
"alpha3": "AFG",
"currencyId": "AFN",
"currencyName": "Afghan afghani",
"currencySymbol": "؋",
"id": "AF",
"name": "Afghanistan"
},
"AI": {
"alpha3": "AIA",
"currencyId": "XCD",
"currencyName": "East Caribbean dollar",
"currencySymbol": "$",
"id": "AI",
"name": "Anguilla"
},
"AU": {
"alpha3": "AUS",
"currencyId": "AUD",
"currencyName": "Australian dollar",
"currencySymbol": "$",
"id": "AU",
"name": "Australia"
}
}
}
这是我的代码:
async function currency() {
const response = await fetch(`https://free.currencyconverterapi.com/api/v5/currencies`);
const json = await response.json();
//console.log(json.results);
for (key in json.results) {
for(x in key){
console.log(x)
}
}
}
请问我做错了什么