fix
This commit is contained in:
1 parent
5eeef0bfd2
commit
c7c870c4fb
1 file changed
-18
@@ -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)
|
|
||||||
Reference in new issue
Block a user