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 → · 使用方法 → · 数据转换工具 →

相关工具