defcheck(raw): try: data = json.loads(raw) except json.JSONDecodeError as e: raise ValueError("返回不是 JSON") from e ifset(data) != {"title", "summary", "items"} ornot data["items"]: raise ValueError("顶层字段无效") ifnotall(isinstance(data[k], str) and data[k].strip() for k in ("title", "summary")): raise ValueError("标题或摘要为空") for x in data["items"]: ifset(x) != {"type", "text", "needs_attention"} or x["type"] notin allowed: raise ValueError("条目字段无效") ifnotisinstance(x["text"], str) ornot x["text"].strip() ornotisinstance(x["needs_attention"], bool): raise ValueError("条目类型无效") return data