中级
实现JSON Schema简化版验证
未完成
中级参考
代码结构已给出,请填写 ____ 处
def solve():
from pyodide.http import open_url
from io import StringIO
raw_requests_csv = open_url(____).read()
import json
USER_SCHEMA = {
'____': '____',
'____': ['____','____','____'],
'____': {
'____': {'____': '____', '____': ____},
'____': {'____': '____'},
'____': {'____': '____'},
'____': {'____': '____', '____': ____, '____': ____},
}
}
TYPE_MAP = {'____': str, '____': int, '____': float, '____': bool, '____': list, '____': dict}
def validate_schema(____):
errors = []
for req in schema.get(____):
if req not in data: errors.append(____)
for field, spec in schema.get(____).items():
val = data.get(____)
if val is None: continue
expected = TYPE_MAP.get(spec.get(____))
if expected and not isinstance(____):
errors.append(____)
if isinstance(____) and '____' in spec and len(____) < spec['____']:
errors.append(____)
if isinstance(____):
if '____' in spec and val < spec['____']: errors.append(____)
if '____' in spec and val > spec['____']: errors.append(____)
return errors
bodies = [
{'____':'____','____':'____','____':'____','____':____},
{'____':'____','____':'____'},
{'____':'____','____':'____','____':'____','____':____},
]
for b in bodies:
errs = validate_schema(____)
print(____)
示例
输入
solve()
期望输出
data=['username', 'email', 'phone', 'age']: VALID data=['email', 'phone']: ['missing required: username'] data=['username', 'email', 'phone', 'age']: ['username: minLength=3', 'age: > maximum']
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199