import typing
import json
from fastapi import FastAPI, Response
from fastapi.encoders import jsonable_encoder
from datetime import datetime
from pydantic import BaseModel
app = FastAPI()
'''
jsonable_encoder
数据序列化
'''
class Item(BaseModel):
name: str
description: typing.Union[str, None] = None
timestamp : datetime
@app.post("/item")
def create_item(item : Item):
print(item)
jsonable_item = jsonable_encoder(item)
json_item = json.dumps(jsonable_item)
return json_item
标签:24,FastAPI,jsonable,encoder,item,json,import,序列化
From: https://www.cnblogs.com/leoshi/p/17255234.html