我想反序列化以下JSON:
[
{
"name": "one",
"path": "/path/to/one"
},
{
"name": "two",
"path": "/path/to/two"
},
{
"name": "three",
"path": "/path/to/three"
}
]
进入Vec<Worskpace>
。 Workspace
定义如下:
#[derive(Serialize, Deserialize)]
struct Workspace {
name: String,
path: String,
}
有没有办法做到这一点,而不必做类似的事情:
#[derive(Serialize, Deserialize)]
struct Workspacesss {
values: Vec<Workspace>,
}
答案 0 :(得分:2)
直接反序列化向量:
let workspaces = serde_json::from_str::<Vec<Workspace>>(input);