fastapi/docs/em/docs/tutorial/encoder.md

43 lines
1.5 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🎻 🔗 🔢
📤 💼 🌐❔ 👆 5⃣📆 💪 🗜 💽 🆎 (💖 Pydantic 🏷) 🕳 🔗 ⏮️ 🎻 (💖 `dict`, `list`, ♒️).
🖼, 🚥 👆 💪 🏪 ⚫️ 💽.
👈, **FastAPI** 🚚 `jsonable_encoder()` 🔢.
## ⚙️ `jsonable_encoder`
➡️ 🌈 👈 👆 ✔️ 💽 `fake_db` 👈 🕴 📨 🎻 🔗 💽.
🖼, ⚫️ 🚫 📨 `datetime` 🎚, 👈 🚫 🔗 ⏮️ 🎻.
, `datetime` 🎚 🔜 ✔️ 🗜 `str` ⚗ 💽 <a href="https://en.wikipedia.org/wiki/ISO_8601" class="external-link" target="_blank">💾 📁</a>.
🎏 🌌, 👉 💽 🚫🔜 📨 Pydantic 🏷 (🎚 ⏮️ 🔢), 🕴 `dict`.
👆 💪 ⚙️ `jsonable_encoder` 👈.
⚫️ 📨 🎚, 💖 Pydantic 🏷, &amp; 📨 🎻 🔗 ⏬:
=== "🐍 3⃣.6️⃣ &amp; 🔛"
```Python hl_lines="5 22"
{!> ../../../docs_src/encoder/tutorial001.py!}
```
=== "🐍 3⃣.1⃣0&amp; 🔛"
```Python hl_lines="4 21"
{!> ../../../docs_src/encoder/tutorial001_py310.py!}
```
👉 🖼, ⚫️ 🔜 🗜 Pydantic 🏷 `dict`, &amp; `datetime` `str`.
🏁 🤙 ⚫️ 🕳 👈 💪 🗜 ⏮️ 🐍 🐩 <a href="https://docs.python.org/3/library/json.html#json.dumps" class="external-link" target="_blank">`json.dumps()`</a>.
⚫️ 🚫 📨 ⭕ `str` ⚗ 💽 🎻 📁 (🎻). ⚫️ 📨 🐍 🐩 💽 📊 (✅ `dict`) ⏮️ 💲 &amp; 🎧-💲 👈 🌐 🔗 ⏮️ 🎻.
!!! note
`jsonable_encoder` 🤙 ⚙️ **FastAPI** 🔘 🗜 💽. ✋️ ⚫️ ⚠ 📚 🎏 😐.