json.decoder.JSONDecodeError: Extra data: line 1 column 4 (char 3)

with open('comments_all.txt',encoding='utf-8') as f:
  lines = f.readlines()
  records_num = len(lines)
  for line in lines:
    comment_id, content_dict = line.split('\t')
    content_dict = json.dumps(content_dict)
    print(content_dict)
    content_dict = json.loads(content_dict.replace("\'", "\""),strict=False)

这是json字符串跟报错

"{'space': '5', 'cost_performance': '3', 'power': '4', 'control': '4', 'comfort': '4', 'oil_consumption': '5', 'apearance': '5', 'decoration': '4', 'Comprehensive score': '4.25', '\u8d2d\u8f66\u76ee\u7684': '\u4e0a\u4e0b\u73ed', 'views': '3975', 'supports': '\u70b9\u8d5e', 'replys': '\u8bc4\u8bba', 'user_id': '4459115', 'comment_id': '0177f7af0w64r3ad1p00000000', 'comment_title': '', 'comment_date': '2012-09-19', 'car_series': '\u4e2d\u534eH530', 'model': '\u4e2d\u534eH530 2011\u6b3e 1.6L \u624b\u52a8\u8c6a\u534e\u578b\u8ba4\u8bc1', '\u884c\u9a76\u91cc\u7a0b': '7650km', '\u767e\u516c\u91cc\u6cb9\u8017': '7.0L', '\u88f8\u8f66\u8d2d\u4e70\u4ef7': '8.58\u4e07', '\u8d2d\u4e70\u65f6\u95f4': '2011-12', '\u8d2d\u4e70\u5730\u70b9': '\u5609\u5174', '\u6700\u6ee1\u610f': '\u7a7a\u95f4\u5927\uff0c\u5916\u89c2\u6f02\u4eae', '\u6700\u4e0d\u6ee1\u610f': '\u6ca1\u6709\u9ed1\u5185\u9970...', '\u7a7a\u95f4': '2700\u8f74\u8ddd\u6446\u5728\u90a3\u91cc...', '\u52a8\u529b': '1.6\u53ea\u80fd\u591f\u5bb6\u7528\uff0c\u559c\u6b22\u8fd0\u52a8\u5efa\u8bae1.5t', '\u64cd\u63a7': '\u8bd5\u9a7e\u5c31\u77e5\u9053\u4e86...', '': '', '\u6cb9\u8017': '\u73b0\u5728\u5dee\u4e0d\u591a5.8\u6bdb\u4e00\u516c\u91cc\uff0c\u7efc\u5408\u8def\u51b5\u534a\u5e02\u533a\u534a\u90ca\u533a', '\u8212\u9002\u6027': '\u4e0d\u9519\uff0c\u81f3\u5c11\u5750\u7740\u4e0d\u96be\u53d7', '\u5916\u89c2': '\u6ca1\u5f97\u8bf4', '\u5185\u9970': '\u53ef\u60dc\u6ca1\u6709\u5168\u9ed1\u5185\u9970', '\u6027\u4ef7\u6bd4': '', '\u9009\u62e9\u8fd9\u6b3e\u8f66\u7684\u7406\u7531': ''}\n"


Traceback (most recent call last):
  File "C:/Users/26779/Desktop/汽车之家_crawler/autohome_crawler/preprocess.py", line 113, in 
    content_dict = json.loads(content_dict.replace("\'", "\""),strict=False)
  File "C:\Users\26779\myProgram\Anaconda3\envs\pytorch\lib\json\__init__.py", line 367, in loads
    return cls(**kw).decode(s)
  File "C:\Users\26779\myProgram\Anaconda3\envs\pytorch\lib\json\decoder.py", line 342, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 4 (char 3)

Process finished with exit code 1

json.decoder.JSONDecodeError: Extra data: line 1 column 4 (char 3)_第1张图片

路过的大神教教我,怎么解决这个问题呢 

 

你可能感兴趣的:(json,服务器,python)