{
"message":"success",
"data":{
"data":[
{
"id":44,
"user":{
"id":22,
"username":"Lcode-0403",
"avatarUrl":"https://avatars.githubusercontent.com/u/58282852?v=4"
},
"content":"博主为啥nuxt内存爆炸啊。啥问题",
"status":1,
"subComments":[
{
"id":45,
"user":{
"id":20,
"username":"SuZiquan",
"avatarUrl":"https://avatars.githubusercontent.com/u/7196781?v=4"
},
"replyToUser":{
"id":22,
"username":"Lcode-0403",
"avatarUrl":"https://avatars.githubusercontent.com/u/58282852?v=4",
"socialSource":"github",
"lastLogin":"2023-03-13 12:47"
},
"content":"Hello,这是一个服务端渲染(Server Side Render)的项目",
"status":1,
"parentId":44,
"createdAt":"2023-03-03 14:59"
}
],
"createdAt":"2023-03-03 01:19"
}
]
}
}
我想响应类似上面格式的json,这是一个java处理返回的结果,我想用go重写。下面是我的数据表
![微信截图_20230314023055.png](https://static.golangjob.cn/230314/20be512c11286f8c0ae84ac2b19acf66.png)
我自己是写了这样的一个结构体,这样的结构体预加载出不来一样的结构,而且还有个subComments字段没有思路。
![微信截图_20230314023231.png](https://static.golangjob.cn/230314/9d614f5cdebdd1ba977c75291d9e0c6e.png)
😭😭😭😭😭😭
更多评论
根结构是JSONData
```go
type JSONData struct {
Message string `json:"message"`
Data DataArray `json:"data"`
}
type User struct {
ID int `json:"id"`
Username string `json:"username"`
AvatarURL string `json:"avatarUrl"`
}
type ReplyToUser struct {
ID int `json:"id"`
Username string `json:"username"`
AvatarURL string `json:"avatarUrl"`
SocialSource string `json:"socialSource"`
LastLogin string `json:"lastLogin"`
}
type SubComments struct {
ID int `json:"id"`
User User `json:"user"`
ReplyToUser ReplyToUser `json:"replyToUser"`
Content string `json:"content"`
Status int `json:"status"`
ParentID int `json:"parentId"`
CreatedAt string `json:"createdAt"`
}
type Data struct {
ID int `json:"id"`
User User `json:"user"`
Content string `json:"content"`
Status int `json:"status"`
SubComments []SubComments `json:"subComments"`
CreatedAt string `json:"createdAt"`
}
type DataArray struct {
Data []Data `json:"data"`
}
```
#2