How to deserialize a JSON file which contains null values using Serde?

后端 未结 2 1371
梦毁少年i
梦毁少年i 2020-12-31 16:51

I want to deserialize the chemical elements JSON file from Bowserinator on github using Serde. For this I created a structure with all the needed fields and derived the need

2条回答
  •  Happy的楠姐
    2020-12-31 17:15

    Any field that can be null should be an Option type so that you can handle the null case. Something like this?

    #[derive(Serialize, Deserialize, Debug, Clone)]
    pub struct Element {
        ...
        color: Option,
        ...
    }
    

提交回复
热议问题