我有一个名为Employee的类,并且有包含Employee实例的列表。我尝试了以下方法:
class Employee:
empId
empName
def __init__(self, empId, empName):
self.empId = empId
self.empName = empName
class Test:
def convertJson(self):
employees=[]
emp1 = Employee(101,'John')
employees.append(emp1)
emp2 = Employee(102,'Smith')
employees.append(emp2)
employeeList = json.dumps(employees.__dict__) # Need to convert employees into json
它引发异常,列表没有属性'dict