use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Msg {
pub mydata: Mdt,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Mdt {
pub info: Vec<(Option<String>,Option<i32>,Option<String>,Option<f64>,Option<i64>,Option<f64>,Option<f64>,Option<String>,Option<i32>,Option<String>)>,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
pub const JS: &str =
r#"{
"mydata": {
"info": [["txt1", 5000, "2023-04-20", -0.1234, 20230419131530, 0.5, -0.05, null, null, "txt2"]]
}
}"#;
let m: Msg = serde_json::from_str(&(JS))?;
match &m.mydata.info[0].9 {
Some(p) => println!("{:?}", p),
None => println!("{:?}", "null")
}
Ok(())
}
This example works when there are no more than 12 elements of info
, because this is a limitation for tuple. How to change tuple (into a structure or array for enum) to work with the number of elements equal to 19. I do right for ten elements?