2023-01-21 15:48:17 +08:00
|
|
|
import json
|
2023-06-17 14:54:30 +08:00
|
|
|
import time
|
2023-01-21 15:48:17 +08:00
|
|
|
|
2023-06-17 14:54:30 +08:00
|
|
|
res = json.loads('{"a": 1, "b": 2, "c": 3}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
2023-01-21 15:48:17 +08:00
|
|
|
|
2023-06-17 14:54:30 +08:00
|
|
|
res = json.loads('{"a": 1, "b": 2, "c": 3, "d": {"e": 4, "f": 5}}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
|
|
|
assert res['d']['e'] == 4
|
|
|
|
assert res['d']['f'] == 5
|
2023-01-21 15:48:17 +08:00
|
|
|
|
2023-06-17 14:54:30 +08:00
|
|
|
res = json.loads(
|
|
|
|
'{"a": 1, "b": 2, "c": 3, "d": {"e": 4, "f": 5}, "g": [6, 7, 8]}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
|
|
|
assert res['d']['e'] == 4
|
|
|
|
assert res['d']['f'] == 5
|
|
|
|
assert res['g'][0] == 6
|
|
|
|
assert res['g'][1] == 7
|
|
|
|
assert res['g'][2] == 8
|
2023-01-21 15:48:17 +08:00
|
|
|
|
2023-06-17 14:54:30 +08:00
|
|
|
res = json.loads(
|
|
|
|
'{"a": 1, "b": 2, "c": 3, "d": {"e": 4, "f": 5}, "g": [6, 7, 8], "h": null}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
|
|
|
assert res['d']['e'] == 4
|
|
|
|
assert res['d']['f'] == 5
|
|
|
|
assert res['g'][0] == 6
|
|
|
|
assert res['g'][1] == 7
|
|
|
|
assert res['g'][2] == 8
|
|
|
|
assert res['h'] is None
|
2023-01-21 15:48:17 +08:00
|
|
|
|
2023-06-17 14:54:30 +08:00
|
|
|
res = json.loads(
|
|
|
|
'{"a": 1, "b": 2, "c": 3, "d": {"e": 4, "f": 5}, "g": [6, 7, 8], "h": null, "i": false}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
|
|
|
assert res['d']['e'] == 4
|
|
|
|
assert res['d']['f'] == 5
|
|
|
|
assert res['g'][0] == 6
|
|
|
|
assert res['g'][1] == 7
|
|
|
|
assert res['g'][2] == 8
|
|
|
|
assert res['h'] is None
|
|
|
|
assert res['i'] is False
|
2023-01-21 15:48:17 +08:00
|
|
|
|
2023-06-17 14:54:30 +08:00
|
|
|
res = json.loads(
|
|
|
|
'{"a": 1, "b": 2, "c": 3, "d": {"e": 4, "f": 5}, "g": [6, 7, 8], "h": null, "i": false, "j": true}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
|
|
|
assert res['d']['e'] == 4
|
|
|
|
assert res['d']['f'] == 5
|
|
|
|
assert res['g'][0] == 6
|
|
|
|
assert res['g'][1] == 7
|
|
|
|
assert res['g'][2] == 8
|
|
|
|
assert res['h'] is None
|
|
|
|
assert res['i'] is False
|
|
|
|
assert res['j'] is True
|
2023-01-21 15:48:17 +08:00
|
|
|
|
2023-06-17 14:54:30 +08:00
|
|
|
res = json.loads(
|
|
|
|
'{"a": 1, "b": 2, "c": 3, "d": {"e": 4, "f": 5}, "g": [6, 7, 8], "h": null, "i": false, "j": true, "k": "string"}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
|
|
|
assert res['d']['e'] == 4
|
|
|
|
assert res['d']['f'] == 5
|
|
|
|
assert res['g'][0] == 6
|
|
|
|
assert res['g'][1] == 7
|
|
|
|
assert res['g'][2] == 8
|
|
|
|
assert res['h'] is None
|
|
|
|
assert res['i'] is False
|
|
|
|
assert res['j'] is True
|
|
|
|
assert res['k'] == 'string'
|
|
|
|
|
|
|
|
res = json.loads(
|
|
|
|
'{"a": 1, "b": 2, "c": 3, "d": {"e": 4, "f": 5}, "g": [6, 7, 8], "h": null, "i": false, "j": true, "k": "string", "l": 1.234}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
|
|
|
assert res['d']['e'] == 4
|
|
|
|
assert res['d']['f'] == 5
|
|
|
|
assert res['g'][0] == 6
|
|
|
|
assert res['g'][1] == 7
|
|
|
|
assert res['g'][2] == 8
|
|
|
|
assert res['h'] is None
|
|
|
|
assert res['i'] is False
|
|
|
|
assert res['j'] is True
|
|
|
|
assert res['k'] == 'string'
|
|
|
|
assert res['l'] == 1.234
|
2023-01-21 15:48:17 +08:00
|
|
|
|
2023-06-18 00:14:03 +08:00
|
|
|
|
|
|
|
# Testing empty object and empty array using type and len
|
|
|
|
res = json.loads('{}')
|
|
|
|
assert type(res) == dict
|
|
|
|
assert len(res) == 0
|
|
|
|
|
|
|
|
res = json.loads('[]')
|
|
|
|
assert type(res) == list
|
|
|
|
assert len(res) == 0
|
|
|
|
|
|
|
|
res = json.loads('{"a": {}}')
|
|
|
|
assert type(res['a']) == dict
|
|
|
|
assert len(res['a']) == 0
|
|
|
|
|
|
|
|
res = json.loads('{"a": []}')
|
|
|
|
assert type(res['a']) == list
|
|
|
|
assert len(res['a']) == 0
|
|
|
|
|
|
|
|
res = json.loads('{"a": 1, "b": {}, "c": []}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert type(res['b']) == dict
|
|
|
|
assert len(res['b']) == 0
|
|
|
|
assert type(res['c']) == list
|
|
|
|
assert len(res['c']) == 0
|
|
|
|
|
|
|
|
res = json.loads(
|
|
|
|
'{"a": 1, "b": 2, "c": 3, "d": {"e": 4, "f": {}}, "g": [6, {}, 8], "h": null, "i": false, "j": true, "k": "string", "l": 1.234}')
|
|
|
|
assert res['a'] == 1
|
|
|
|
assert res['b'] == 2
|
|
|
|
assert res['c'] == 3
|
|
|
|
assert res['d']['e'] == 4
|
|
|
|
assert type(res['d']['f']) == dict
|
|
|
|
assert len(res['d']['f']) == 0
|
|
|
|
assert res['g'][0] == 6
|
|
|
|
assert type(res['g'][1]) == dict
|
|
|
|
assert len(res['g'][1]) == 0
|
|
|
|
assert res['g'][2] == 8
|
|
|
|
assert res['h'] is None
|
|
|
|
assert res['i'] is False
|
|
|
|
assert res['j'] is True
|
|
|
|
assert res['k'] == 'string'
|
|
|
|
assert res['l'] == 1.234
|
|
|
|
print('PASS')
|