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

Python如何从指定JSON结构提取producers多条目为逗号分隔字符串

解决方案

你当前的问题根源是metadata['plist']['dict']['array'][2]['dict']['string']对应的是存储多个producer值的数组,不是单个字符串,直接取值只会拿到首个元素或触发类型错误,可通过如下代码提取并拼接为逗号分隔的字符串:

# 提取所有producer条目到列表
producers_list = metadata['plist']['dict']['array'][2]['dict']['string']
# 拼接为逗号分隔的字符串
producers_result = ', '.join(producers_list)
# 输出结果
print("Producers: ", producers_result)

如果需要过滤空值、去除首尾空格,可以使用过滤逻辑:

producers_list = metadata['plist']['dict']['array'][2]['dict']['string']
# 过滤空值、去除每个条目的首尾空白字符后再拼接
producers_result = ', '.join([item.strip() for item in producers_list if item.strip()])
print("Producers: ", producers_result)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 07:54:08