Is it possible to have a struct with multiple JSON tags?

后端 未结 2 1233
情深已故
情深已故 2021-01-19 04:16

I post a request to a server and get a reply in JSON format. I\'m able to unmarshal it to a struct. Then I need to create a new JSON file with the same data but different JS

2条回答
  •  离开以前
    2021-01-19 04:24

    What is possible though, with 2 identically laid out structs (namin, types and ordering of fields needs to match exactly) is to cast from one to the other. I would be very cautious of doing this though and make sure the 2nd type (bar in your example) is unexported to prevent from being used elsewhere.

    https://play.golang.org/p/y8EH1U9_3jN

提交回复
热议问题