pikapython/test/python/json/json_loads.py

98 lines
2.5 KiB
Python
Raw Normal View History

2023-01-21 15:48:17 +08:00
import json
import time
2023-01-21 15:48:17 +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
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
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
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
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
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
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
print('PASS')
2023-01-21 15:48:17 +08:00