从文件读取json时遇到以下错误
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 2 column 1 (char 948)
使用以下脚本从文件中读取json内容
import json
if __name__ == "__main__":
file_path = "D:\\Freelancing\\Scraping_football_historic_data\\Data\\1.138103502"
with open(file_path,'r') as datafile:
dict_data = json.load(datafile)
print(dict_data)
在搜索答案时,这个question的答案建议我在json字符串之前添加 r 。
在上述情况下,或者如果有更好的方式读取文件,该怎么办。 ?
可以从pastebin链接读取文件的内容: https://pastebin.com/ZyyrtcZW
答案 0 :(得分:1)
您在每个字典之间都缺少逗号,您的数据应该像这样
....
{"op":"mcm","clk":"5733948534","pt":1514206953689,"mc":[{"id":"1.138103502","rc":[{"ltp":2.02,"id":48756}]}]},
{"op":"mcm","clk":"5739085003","pt":1514309273736,"mc":[{"id":"1.138103502","rc":[{"ltp":2.0,"id":48756}]}]},
{"op":"mcm","clk":"5739711407","pt":1514327265235,"mc":[{"id":"1.138103502","rc":[{"ltp":2.06,"id":48756}]}]},
.....