Rust Requires Chilkat v11.4.0+
Rust
Example: JsonObject.NewArrayOf method
See more JSON Examples
Demonstrates theNewArrayOf method.
Chilkat Rust Downloads
let big_cats = "[\"lion\",\"tiger\",\"leopard\",\"jaguar\",\"cheetah\",\"snow leopard\",\"clouded leopard\",\"cougar\",\"puma\",\"panther\"]".to_string();
let json = chilkat::JsonObject::new();
let _ = json.update_string("test", "abc");
if json.new_array_of("big_cats", &big_cats).is_err() {
println!("{}", json.last_error_text());
return;
}
json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());
// Result:
// {
// "test": "abc",
// "big_cats": [
// "lion",
// "tiger",
// "leopard",
// "jaguar",
// "cheetah",
// "snow leopard",
// "clouded leopard",
// "cougar",
// "puma",
// "panther"
// ]
// }