dongwen4487 2014-03-18 10:12
浏览 60

将JSON对象“按原样”存储到数据存储区中

I have to store a nested struct into datastore. As I'm running into the

datastore: flattening nested structs leads to a slice of slices: field

problem, I'd like to store the JSON object as is (as string?) to the datastore. Is this doable in Go?

  • 写回答

2条回答 默认 最新

  • doudi2520 2014-03-18 10:33
    关注

    You should be able to store the json.RawMessage. See the example in the package docs.

    RawMessage is a raw encoded JSON object. It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding.

    It's a slice of byte, but you can easily convert it to a string if you wish.

    评论

报告相同问题?