From c7c870c4fb2b9932459d22c25b2cf0ea5d0e669d Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Wed, 5 Apr 2023 00:47:26 +0800 Subject: [PATCH] fix --- toJson.py | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 toJson.py diff --git a/toJson.py b/toJson.py deleted file mode 100644 index 811e6cd..0000000 --- a/toJson.py +++ /dev/null @@ -1,18 +0,0 @@ -import json -from typing import Any - -class User: - name = "cwx" - value = "val" - -class MyJsonEncoder(json.JSONEncoder): - def default(self, o: Any) -> Any: - if isinstance(o,User): - return { - "name": o.name, - "value": o.value - } - return super().default(o) - -s = json.dumps(User(),cls=MyJsonEncoder,ensure_ascii=False) -print(s) \ No newline at end of file