Json dump

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# --------------------------------------------------------- #
tags = ['Python', 'Json', 'Python基本']
# --------------------------------------------------------- #

import json


class SampleVal:

    def __init__(self):

        self.val = 10
        self.foo = "var"


class Encode(json.JSONEncoder):

    def default(self, o):

        print(o)

        return json.JSONEncoder.default(self, o)


a = SampleVal()

js = json.dumps(a, cls=Encode)

js.

最終更新日: 2022-06-15 15:27:01