🔍

首页Home › 开发工具Developer Tools

💎 JSON 转 Crystal 类JSON to Crystal Class

根据 JSON 生成 Crystal 语言的类或结构体,使用标准库 JSON::Serializable,自动推断 String、Int32/Int64、Float64、Array 等类型,可空字段生成 T? 类型并用注解映射原始键名。Generate Crystal classes or structs from JSON using the standard JSON::Serializable module, with inferred String, Int32/Int64, Float64 and Array types, nilable T? fields and annotations for original key names.

使用说明与常见问题How-to & FAQ

「JSON 转 Crystal 类」是什么?What is the JSON to Crystal Class tool?

根据 JSON 生成 Crystal 语言的类或结构体,使用标准库 JSON::Serializable,自动推断 String、Int32/Int64、Float64、Array 等类型,可空字段生成 T? 类型并用注解映射原始键名。Generate Crystal classes or structs from JSON using the standard JSON::Serializable module, with inferred String, Int32/Int64, Float64 and Array types, nilable T? fields and annotations for original key names.

如何使用「JSON 转 Crystal 类」?How do I use the JSON to Crystal Class?

粘贴 JSON 并填写根类名,选择 class 或 struct,下方生成 Crystal 代码,用 Root.from_json(text) 解析、root.to_json 序列化。Paste JSON, set the root name and choose class or struct; then parse with Root.from_json(text) and serialize with root.to_json.

可空字段在 Crystal 中怎么处理?How are nilable fields handled?

JSON 中可能缺失或为 null 的字段会生成 T?(即 T | Nil),JSON::Serializable 在键不存在时自动赋值 nil,使用前需要判断或用 .try。Fields that may be missing or null become T? (T | Nil); JSON::Serializable sets nil when the key is absent, so check it or use .try before use.

class 和 struct 应该选哪个?class or struct?

struct 是值类型、分配在栈上,适合小而不可变的数据;class 是引用类型,适合需要共享或修改的对象。不确定时用 class。A struct is a stack-allocated value type, good for small immutable data; a class is a reference type for shared or mutable objects. Use class if unsure.

「JSON 转 Crystal 类」免费吗?数据会上传吗?Is the JSON to Crystal Class free? Is my data uploaded?

「JSON 转 Crystal 类」完全免费,无需注册或安装,手机和电脑都能用;所有处理都在你的浏览器本地完成,输入的内容和文件不会上传到服务器。The JSON to Crystal Class is completely free with no sign-up or install and works on phones and desktops; everything runs locally in your browser and nothing you enter is uploaded.

相关工具Related tools

🟦 JSON 转 TypeScriptJSON to TypeScript Interface🐹 JSON 转 Go 结构体JSON to Go Struct☕ JSON 转 Java 实体类JSON to Java POJO💠 JSON 转 C# 实体类JSON to C# Class🐍 JSON 转 Python 字典/列表JSON to Python Dict Converter🟣 JSON 转 Kotlin 数据类JSON to Kotlin Data Class🕊️ JSON 转 Swift CodableJSON to Swift Codable🦀 JSON 转 Rust 结构体(serde)JSON to Rust Struct (serde)📐 JSON Schema 生成器JSON Schema Generator🧾 JSON 格式化校验JSON Formatter & Validator

← 全部工具All tools