Vin*_*yen 1 javascript api rest axios
我有一个axios获取请求,如:
axios.get(url + '?hapikey=' + copyFrom)
.then(res => console.log(res.data));
Run Code Online (Sandbox Code Playgroud)
返回类似于以下内容的响应:
{ name: 'Name',
anObject: [
{
id: 1,
nestedObject: [Object]
}
]
}
Run Code Online (Sandbox Code Playgroud)
如何获得的响应nestedObject以显示其字段/值对,或者是直接在中查询它的唯一方法.then?
深入打印对象的最简单方法是使用JSON.stringify,例如:
axios.get(url + '?hapikey=' + copyFrom)
.then(res => console.log(JSON.stringify(res.data)));
Run Code Online (Sandbox Code Playgroud)
正如@PatrickRoberts所说,您可以使用可选参数进行漂亮打印
axios.get(url + '?hapikey=' + copyFrom)
.then(res => console.log(JSON.stringify(res.data, null, 2)));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1417 次 |
| 最近记录: |