python - 从文件python将'r'添加到json字符串
问题描述
从文件中读取 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)
在寻找答案时,这个问题有一个答案,建议我在 json 字符串之前添加r 。
在上述情况下如何完成,或者是否有更好的方法来读取文件。?
该文件的内容可以从 pastebin 链接中读取: https ://pastebin.com/ZyyrtcZW
解决方案
您在每个单独的字典之间都缺少逗号,您的数据应该看起来像
....
{"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}]}]},
.....
推荐阅读
- javascript - 如何使用按钮从类中调用方法?
- sql - SQL Server 填补时间序列中的空白
- iis - AwStats IIS 自定义字段不解析
- r - 用二进制数据获取r中不同组合的频率
- angular - Angular mat-select 在单击之前不可见,如何设置默认值
- python - 将 JSON 从 Web API 转换为 pandas 数据框
- discord.js - 未处理的承诺拒绝警告异步
- java - 使用 java 和 libpst 从 PST 文件中提取 msg 文件
- python - 如何根据特定的顺序在数组中赋值
- java - 你如何在 Java 中找到这棵树的路径数?