PyComicPackRouMan/toJson.py
2023-04-05 00:12:18 +08:00

18 lines
407 B
Python

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)