【问题标题】:Merge multiple JSON files outputs in one list object将多个 JSON 文件输出合并到一个列表对象中
【发布时间】:2021-05-28 11:41:17
【问题描述】:

我有一个包含许多 JSON 文件的文件夹。我想编写 Python 代码来扫描所有文件,读取它们并将它们合并到一个列表对象中。

我尝试了以下方法。

mypath = 'C:/Users/data'
files = ['f1.josn', 'f2.josn', ..., 'f20.josn']
output_list = []
for file in files:
    with open(mypath+'/'+file, encoding='utf-8') as infile:
        output_list.append(json.load(infile))

我在运行上面的代码后得到了一个回溯:

JSONDecodeError: Invalid control character at: line 1002 column 99 (char 38611)

【问题讨论】:

    标签: python json list


    【解决方案1】:

    问题出在一个(或全部)json 文件中。引用this页面:

    如果要反序列化的数据不是有效的 JSON 文档,则会引发 JSONDecodeError。

    【讨论】:

      猜你喜欢
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      • 2016-04-30
      • 2022-11-02
      • 1970-01-01
      相关资源
      最近更新 更多