Initalizing the nested anonymous structures

前端 未结 1 441
误落风尘
误落风尘 2021-01-29 14:49

I am having a json as

{
\"fields\": [\"time\",\"id\",\"status\",\"customerId\",\"additionalDetail\"],
\"pageInfo\": {\"start\": 0, \"rows\": 1000}
}


        
相关标签:
1条回答
  • 2021-01-29 15:24

    This works, but it is ugly:

    bd := RBody { Fields :  []string{"time","id","status","customerId","additionalDetail"},
    PageInfo : struct {Start int `json:"start"`
    Rows int `json:"rows"`} {Start:1,Rows:2}}
    

    I suggest you either name the anonymous struct, or initialize Fields in the declaration, and PageInfo using assignments later.

    0 讨论(0)
提交回复
热议问题