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

JavaScript中查找指定JSON键值:如何获取API返回JSON内的导演姓名

你可以直接用数组的实例方法实现筛选,默认你从接口获取的JSON已经解析为对象存在out变量中:

场景1:只有1名导演(常用场景)

使用find方法匹配第一个符合条件的剧组人员:

const director = out.credits.crew.find(item => item.job === 'Director')
// 增加容错逻辑,避免无导演信息时报错
if (director) {
  console.log(director.name)
} else {
  console.log('未查询到导演信息')
}

场景2:存在多名联合导演

使用filter方法匹配所有符合条件的剧组人员,遍历打印所有导演姓名:

const directorList = out.credits.crew.filter(item => item.job === 'Director')
directorList.forEach(director => console.log(director.name))

补充说明

如果你从接口拿到的是未解析的原始JSON字符串,需要先调用JSON.parse()转换为JS对象再操作:

const out = JSON.parse(接口返回的原始JSON字符串)
// 后续执行上述筛选逻辑即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 13:36:02