Python: How to decode enum type from json
问题 class MSG_TYPE(IntEnum): REQUEST = 0 GRANT = 1 RELEASE = 2 FAIL = 3 INQUIRE = 4 YIELD = 5 def __json__(self): return str(self) class MessageEncoder(JSONEncoder): def default(self, obj): return obj.__json__() class Message(object): def __init__(self, msg_type, src, dest, data): self.msg_type = msg_type self.src = src self.dest = dest self.data = data def __json__(self): return dict (\ msg_type=self.msg_type, \ src=self.src, \ dest=self.dest, \ data=self.data,\ ) def ToJSON(self): return json