This question already has answers here:
JavaScript property access: dot notation vs. brackets?
(13个回答)
Dynamically access object property using variable
(15个答案)
在10个月前关闭。
如何访问名称包含数字,点和空格的对象属性?
我的REST API响应是:
此表示法不起作用:
(13个回答)
Dynamically access object property using variable
(15个答案)
在10个月前关闭。
如何访问名称包含数字,点和空格的对象属性?
我的REST API响应是:
{
"Global Quote": {
"01. symbol": "WDI.FRK",
"02. open": "147.5000",
"03. high": "150.1000",
"04. low": "130.3000",
"05. price": "139.7500",
"06. volume": "79625",
"07. latest trading day": "2019-05-31",
"08. previous close": "154.0000",
"09. change": "-14.2500",
"10. change percent": "-9.2532%"
}
}
此表示法不起作用:
var data = response;
var price= data.Global%x20Quote.05.%x20price;
最佳答案
这应该起作用:const price = data['Global Quote']['05. price']
09-11 15:31