In Golang I can write:
type Person struct {
Id int `json:"id"`
}
Then on JSON.Marshal(Person{})
, I get {"id": 0}
. That is possible due to the json
tag related to the Id
field. Furthermore, I can provide any custom information in the tag section and treat it later using reflect on the struct.
Is there some analogy in C++, where I can provide additional info for a field?
答案 0 :(得分:3)
不。 C ++在该语言中没有任何序列化支持。您必须使用代码编写它,或者可以使用第三方工具和库,例如Cereal,Boost.Serialization,FlatBuffers,ThorSerializer,Cap'n Proto等。