raise JSONDecodeError(“Extra data“, s, end) json.decoder.JSONDecodeError: Extra data: line 1 column

raise JSONDecodeError("Extra data", s, end)

json.decoder.JSONDecodeError: Extra data: line 1 column错误处理

先去掉外面的列表,再用正则解决

import json
import re
of = open('cookie.txt','r',encoding='utf-8')
cookies = []
r = of.read()[1:-1]
pattern = r'({.*?})'
r1 = re.findall(pattern,r)
for i in r1:
    dic = json.loads(i)
    cookies.append(dic)
of.close()

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