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

如何移除JSON响应中的冗余键?含外层数字键与entry_id

移除JSON响应中的冗余外层数字键与entry_id字段

没法在fetch请求过程中直接移除这些冗余键,必须在拿到响应数据后进行处理。你可以修改getEntries函数,在解析完JSON后对数据做清洗:

async function getEntries(){
    const response = await fetch(url, {
        headers: {
          Authorization: `Basic ${btoa(`${username}:${password}`)}`
        }
      })
    const json = await response.json();
    // 移除外层数字键,同时删除每个条目中的entry_id
    const cleanedEntries = Object.values(json).map(({ entry_id, ...rest }) => rest);
    return cleanedEntries;
};

代码说明:

  • Object.values(json):把外层以数字为键的对象转换成数组,直接丢弃那些数字键
  • .map(({ entry_id, ...rest }) => rest):用对象解构语法,把每个条目中的entry_id剔除,只保留剩下的字段

处理后你会得到这样的数组:

[
  {
    user_id: '0',
    date_created: '2023-09-21 16:17:10',
    value: 'text'
  },
  {
    user_id: '0',
    date_created: '2023-09-27 15:57:43',
    value: 'text'
  },
  {
    user_id: '0',
    date_created: '2023-09-29 20:21:33',
    value: 'text'
  }
]

内容的提问来源于stack exchange,提问作者Jack Morris

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 20:33:19