我有一个JSON字符串列表,我正在将它们转换为一个dict列表。
  
  
   我这样做是为了将它们合并到一个最终的JSON字符串中,稍后再转换为熊猫数据帧:
  
  s1 = '{ "id": 11, "label": "REF", "claim": "Lorelai Gilmore", "ce": [[[1,2, "Gilmore", 3]]]}'
s2 = '{ "id": 0, "label": "REF", "claim": "named Robert s.", "ce": [[[1,2, "Lorelai", 3]]]}'
s = [s1, s2]
combine = [json.loads(item) for item in s]
r = json.dumps(combine, indent=2)
s = pandas.read_json(r)
print(s)
  
   我拥有的JSON字符串列表非常大,因此我尝试使用TQDM进度条来监控进度:
  
  combine = tqdm([json.loads(item) for item in s])
  
   但我得到了这个错误:
  
    0%|          | 0/2 [00:00<?, ?it/s]Traceback (most recent call last):
  File "D:/OneDrive/PhD/fever_challenge/test.py", line 11, in <module>
    r = json.dumps(combine, indent=2)
  File "C:\Python35\lib\json\__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "C:\Python35\lib\json\encoder.py", line 200, in encode
    chunks = list(chunks)
  File "C:\Python35\lib\json\encoder.py", line 436, in _iterencode
    o = _default(o)
  File "C:\Python35\lib\json\encoder.py", line 179, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError:   0%|          | 0/2 [00:00<?, ?it/s] is not JSON serializable
  
   在跟踪错误时,我删除了代码中的最后三行,并观察到循环被卡住了。这就是我所看到的:
  
    0%|          | 0/2 [00:00<?, ?it/s]
  
   我的代码有什么问题?