我有一个JSON,其中一个键包含一个对象数组,我只对其中的一个字符串感兴趣:
{
"actors": [{
"name": "Bob",
"foo": "bar"
}, {
"name": "Jim",
"foo": "baz"
}],
"fruits": [{
"name": "Pineapple",
"foo": "bar"
}, {
"name": "Apple",
"foo": "baz"
}]
}
我有
use serde::Deserialize; // 1.0.110
#[derive(Deserialize)]
pub struct Name {
pub name: String,
}
#[derive(Deserialize)]
pub struct Data {
pub actors: Vec<Name>,
pub fruits: Vec<Name>,
}
我该如何展平,以便拥有Vec<String>
而不是Vec<Name>
?例如我想结束
actors: ["Bob", "Jim"],
fruits: ["Pineapple", "Apple"],