I'm trying to decode this data:
{
"ok": true,
"people": [
{
"name": "John",
"age": "10"
}
]
}
Into a struct.The code is:
extern crate rustc_serialize;
use rustc_serialize::json;
#[derive(RustcDecodable)]
struct Man {
name: String,
age: i32,
}
#[derive(RustcDecodable)]
struct Men {
ok: bool,
people: [Man; 16],
}
...
let json: Men = json::decode(&data).unwrap();
...
The problem is that when the length of the array in Men doesn't match the length of corresponding field in JSON exactly, this error happens:
thread '<main>' panicked at 'called `Result::unwrap()`
on an `Err` value: ApplicationError("wrong array length")',
../src/libcore/result.rs:738
Any ideas on how to deal with this? General code style advice is also welcome.