So basically, I'm trying to deserialize a JSON file into a hashmap<String,String> using the serde crate, but. The JSON file:
"
[
{
"orchard_name": "Happy Apple",
"tons": "5"
},
{
"orchard_name": "Munch for Lunch",
"tons": "2"
}
]
"
This is my structure:
#[derive(Serialize, Deserialize, Debug)]
struct OrangeFarm
{
map : HashMap<String,String>
}
and this is where I try to do the deserialization:
let res = serde_json::from_str(_json);
if res.is_ok() {println!("Deserealization worked."); }
else { println!("it went wrong"); }
let mut deserializedFarm : OrangeFarm = res.unwrap();
For some reason, it works if I delete the second {}, but it doesn't if I let the second {} as I get this error "thread 'main' panicked at 'called Result::unwrap() on an Err value: Error("trailing characters" . Do you have any idea why this happens? Thank you!