无法将对象转储到json文件

时间:2017-06-19 08:56:26

标签: python html json

我正在尝试将python对象转储到json文件。

with open('test.json', mode='w', encoding='utf-8') as f:
    json.dump([a], f)

但我收到了这个错误:

Traceback (most recent call last):

File "/Users/Lee/Desktop/BeautyProductsScraping-master2/test.py", line 30, in <module>
    json.dump([a], f)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 178, in dump
    for chunk in iterable:
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/encoder.py", line 427, in _iterencode
    yield from _iterencode_list(o, _current_indent_level)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/encoder.py", line 324, in _iterencode_list
    yield from chunks
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/encoder.py", line 403, in _iterencode_dict
    yield from chunks
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/encoder.py", line 436, in _iterencode
    o = _default(o)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/encoder.py", line 180, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <!DOCTYPE html>

如何处理我对象中的html?

0 个答案:

没有答案