【发布时间】:2020-09-11 01:30:28
【问题描述】:
我正在尝试接收以下 JSON:
{
"va": "{1: 5, 2:1, 3:5}"
}
在我的 main.py 中,我有以下内容:
from typing import Optional, Dict
from fastapi import FastAPI
from pydantic import BaseModel
class rq(BaseModel):
va: Dict[str, str]
app = FastAPI(debug=True)
@app.post("/hello")
async def create_item(rq: rq):
return 1
但我明白了
"msg": "值不是有效的字典", "type": "type_error.dict"
我如何接收 va 作为 dict 来迭代它?
【问题讨论】:
标签: python-3.x fastapi pydantic