Sample code for 30+ languages & platforms
Rust

Load a JSON Array

See more JSON Examples

The Chilkat JSON API requires the top-level JSON to be an object. Therefore, to load an array requires that it first be wrapped as an object.

Chilkat Rust Downloads

Rust

// Imagine we want to load this JSON array for parsing:
let json_array_str = "[{\"id\":200},{\"id\":196}]".to_string();

// First wrap it in a JSON object by prepending "{ "array":" and appending "}"
let sb_json = chilkat::StringBuilder::new();
let _ = sb_json.append("{\"array\":");
let _ = sb_json.append(&json_array_str);
let _ = sb_json.append("}");

let json = chilkat::JsonObject::new();
let _ = json.load(&sb_json.get_as_string().unwrap_or_default());

// Now we can get the JSON array
let j_array = json.array_at(0).unwrap();

// Do what you want with the JSON array...
// For example:
let j_obj_id = j_array.object_at(0).unwrap();
println!("{}", j_obj_id.int_of("id"));