Skip to content

Commit 4d02eb6

Browse files
authored
Update json_ex.py
1 parent 044330b commit 4d02eb6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Python/json/json_ex.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
j = json.loads(data)
55
print(j['two'])
66

7+
8+
import json
9+
10+
class Student:
11+
def __init__(self, id, name, password):
12+
self.id = id
13+
self.name = name
14+
self.password = password
15+
16+
stud1 = Student(1,'Tan Ah Kau','123456')
17+
18+
# Convert Python object to JSON object
19+
json1 = json.dumps(stud1.__dict__, separators=(',', ':'))
20+
print(json)
21+
722
'''
823
2
24+
{"password":"123456","id":1,"name":"Tan Ah Kau"}
925
'''

0 commit comments

Comments
 (0)