Closed ape-casear closed 7 months ago
found out
pub fn proto_to_json() {
let mut t = pa::Token::new();
t.set_token_id("我是token".to_string());
t.set_bool_value(true);
t.set_herAge("23".to_string());
let options = PrintOptions {
proto_field_name: true,
..Default::default()
};
println!("default is {:?}", options);
match print_to_string_with_options(&t, &options) {
Ok(str) => {
println!("json is {}", str);
}
Err(e) => {
eprintln!("e is {}", e);
}
}
}
the solution is passing PrintOptions to fn print_to_string_with_options.
given a proto
lib.rs
I need the output to be {"token_id": "我是token", "bool_value": true}
how to approach that?