-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
31 lines (23 loc) · 1.07 KB
/
test.py
File metadata and controls
31 lines (23 loc) · 1.07 KB
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
30
31
from jsontools import JsonObject, StaticJsonField, DynamicJsonField
class Test_JsonObject(JsonObject):
name = StaticJsonField("name", "kamran")
birthDay = StaticJsonField("birthDay", 1993)
print("\ncreate instance with default value +++++++++++++++++++++++++++")
instance = Test_JsonObject()
print(instance.getJson())
print(instance.name)
print("\nadd json attribute's like variable's +++++++++++++++++++++++++++")
instance.nation = DynamicJsonField(instance, "nation", "iraninan")
print(instance.getJson())
print("\nchange default value by a json +++++++++++++++++++++++++++")
instance.setJson('{"name":"unknown", "nation":"iraninan"}')
print(instance.getJson())
print(instance.nation)
print("\nload json to a new instance +++++++++++++++++++++++++++")
instance = Test_JsonObject.fromJson('{"name":"unknown", "nation":"iraninan"}')
print(instance.getJson())
print(instance.nation)
print("\ncreate instance by a dict +++++++++++++++++++++++++++")
instance = Test_JsonObject({"name": "unknown", "nation": "iraninan"})
print(instance.getJson())
print(instance.nation)