JSONtoRustStruct:快速上手指南

第一次使用就能成功所需的全部內容:該貼上什麼、哪個選項真正重要、以及如何讀懂結果。

輸入 JSONtoRustStruct 輸出 100% 在瀏覽器內執行——資料不會離開您的裝置。
JSONtoRustStruct — 輸入 → 輸出. 100% 在瀏覽器內執行——資料不會離開您的裝置。

使用方法

  1. 開啟工具,將內容貼上到左側輸入框。
  2. 只調整任務真正需要的選項——多數情況下預設值就是正確的。
  3. 在右側檢視結果,輸入時結果會即時更新。
  4. 用「複製」取走結果,或用「下載」儲存為檔案。
使用方法 · JSONtoRustStruct 1 將資料貼上到輸入框(或載入範例)。 2 依目標格式或使用情境調整選項。 3 複製、下載或檢視輸出——輸入時結果即時更新。
使用方法 — 3

範例

Emits serde rename attributes so the Rust field names can stay idiomatic.

輸入

{"id":42,"title":"Hello","tags":["a","b"],"active":true}

輸出 — 搜尋結果

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
    #[serde(rename = "id")]
    pub id: i64,
    #[serde(rename = "title")]
    pub title: String,
    #[serde(rename = "tags")]
    pub tags: Vec<String>,
    #[serde(rename = "active")]
    pub active: bool,
}

執行

說明

Generate a serde-derived Rust struct with rename attributes from a JSON sample.

JSONtoRustStruct → · 使用方法 → · 資料轉換工具 →

相關工具