serde_json - 如何使我的结构可从/转换为 json?

serde_json - how to make my struct convertable from / to json?

查看 the documentation of serde_json, I can't understand what trait I have to implement to make a struct serializiable to and deserializiable from json. The obvious answer could be Deserializer and Serializer 但这些是结构,而不是特征。

使用 rustc-serialize 我可以实现 ToJsonFromJson 特征。

来自crate index page

Serde provides a mechanism for low boilerplate serialization & deserialization of values to and from JSON via the serialization API. To be able to serialize a piece of data, it must implement the serde::Serialize trait. To be able to deserialize a piece of data, it must implement the serde::Deserialize trait. Serde provides provides an annotation to automatically generate the code for these traits: #[derive(Serialize, Deserialize)].

-- Creating Json by Serializing Data Structures