You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Axios调用API获取JSON数据时,destination返回undefined问题排查

问题原因及解决方法

问题出在数据层级的嵌套上,你忽略了API返回结构里的双层data嵌套:

从你提供的API返回JSON可以看到,Axios的response.data对应的是最外层的data对象,而你要找的destination字段在这个外层对象内部的另一个data子对象里。

修正后的代码

axios.request(options).then(function (response) {
  // 补充一层 .data 访问内部业务数据对象
  console.log(response.data.data.destination);
}).catch(function (error) {
  console.error(error);
});

结构拆解

API返回的核心结构(简化后):

{
  "data": {
    "data": {
      "destination": "INDB",
      // 其他业务字段...
    },
    "message": "Success",
    "status": true,
    "timestamp": 1661021331914
  }
}
  • response.data → 对应最外层的容器对象,包含data、message、status等元信息字段
  • response.data.data → 对应实际的业务数据对象,里面才包含destination、source等你需要的具体字段

你之前的代码少了一层.data,自然找不到目标字段,返回undefined。

内容的提问来源于stack exchange,提问作者vatsal mandloi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 08:24:53