Rust 将字段序列化为camelCase
示例
extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; #[derive(Serialize)] struct Person { #[serde(rename="firstName")] first_name: String, #[serde(rename="lastName")] last_name: String, } fn main() { let person = Person { first_name: "Joel".to_string(), last_name: "Spolsky".to_string(), }; let json = serde_json::to_string_pretty(&person).unwrap(); //印刷品: // //{ // "firstName": "Joel", // "lastName": "Spolsky" //} println!("{}", json); }