将字段序列化为 camelCase
use serde::Serialize; #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct Person { first_name: String, last_name: String, } fn main() { let person = Person { first_name: "Graydon".to_string(), last_name: "Hoare".to_string(), }; let json = serde_json::to_string_pretty(&person).unwrap(); // 打印输出: // // { // "firstName": "Graydon", // "lastName": "Hoare" // } println!("{}", json); }