0
繼續學習Go。與golang的json的SQL關係
如果我有一個mysqp/PG數據庫如文章和評論表關係
Post id, title
Comments id, post_id, comment
我想有這樣的JSON表示:
{
id: 1
title: "A blog post"
comments: [
{id: 1, comment: "This is comment 1"},
{id: 2, comment: "This is comment 2"}
]
}
我能抓住帖子並顯示json,而不是評論。我想我需要在Post結構中有一個Comment結構數組。只是不知道如何將它們結合在一起,尤其是掃描行。
一個顯示從這樣的關係中輸出json的例子會很棒。
謝謝!效果很好。 – robzolkos
@EveFreeman,你能否再次讓這個要點可用:)? –
完成!對不起,我改回了我的github用戶名。 –