javascript - 通过Javascript读取Object的属性
问题描述
我正在尝试从对象文本中提取价格值。我收到未定义的值。请任何建议。
const fetch = require('node-fetch');
console.log('1. lets start')
fetch('https://api.binance.us/api/v3/avgPrice?symbol=DOGEUSD')
.then(res => res.text())
.then(text => {
console.log(text['price']);
})
解决方案
将 text() 更改为 json(),以获取 json 对象:
const fetch = require('node-fetch');
console.log('1. lets start')
fetch('https://api.binance.us/api/v3/avgPrice?symbol=DOGEUSD')
.then(res => res.json())
.then(res => {
console.log(res['price']);
})
推荐阅读
- git - 是否可以将整个 git commit 历史记录下载为列表?
- python - 通过多个列表并行迭代,并在迭代项上建立索引
- sqlite - 如何在 ALTER 查询之前检查 TABLE 是否存在?
- python - 如何在 S3 中的 Pyspark 中使用包含子文件夹的文件夹中的 CSV 文件创建新的数据框
- windows - 如何从 startActivity (intent) 的内置 UI 中删除取消按钮,
- python - Pandas:使用部分字符串搜索结果创建列
- html - angular - html - 字体真棒图标在 div 的右侧未对齐
- css - 如何使我的卡片不那么宽并且有 3 列
- r - 绘制两个图得到错误:无法将类列表的对象转换为 grob
- angular - 当具有元数据依赖项时,Angular 7服务返回未定义