我正在尝试编辑json文件,以便可以从PyQt5 QlistWidget保存联系信息。
我的错误: TypeError:无法散列的类型:'QListWidgetItem'
JSON文件: {“ test1”:“ test1”,“ test2”:“ test2”,“ test3”:“ test3”}
def delPerson(name=dlg.lineEdit_name.text(), phone=dlg.lineEdit_phone.text()):
for item in dlg.listWidget.selectedItems():
dlg.listWidget.takeItem(dlg.listWidget.row(item))
with open("data.json","r") as file:
data = json.load(file)
del data[name]
print(data)
with open("data.json", "w") as file:
json.dump(data, file)
dlg.listWidget.itemClicked.connect(delPerson)