我想比较从JSON文件中读取的键值是否存在当前日期,以此判断今天是否已经记录了数据,以避免重复记录。但是这种方法似乎无法返回True,即使日期存在也是如此。
def removeJsonDupes(JSONcompleteFilePath, date):
with open(JSONcompleteFilePath, "r") as file:
dictionary = json.load(file)
if dictionary.get("date") is str(date):
dateRecorded = True
print(date, "is in the dict")
else:
dateRecorded = False
print(date, "is not in the dict")
return dateRecorded
JSON 内容:
{
"prices": [
{
"date": "07/12/21",
"prices": [
"2.49",
"1.61"
]
}
]
}