如何正確解析 json 我有以下 json 文件{ "hello": { "title": "Golang", "story": [ "Go lang story", "Channel story" ], "options": [ { "text": "That story", "arc": "west" }, { "text": "Gee", "arc": "east" } ] }, "world": { "title": "Visiting", "story": [ "Boo", "Doo", "Moo", "Qoo" ], "options": [ { "text": "weird", "arc": "west" }, { "text": "funny", "arc": "north" } ] }}我為內部創建了這些結構type chapter struct{ Title string `json:"title"` Story []string `json:"story"` Option []option `json:"options"`}type option struct { Text string `json:"text"` Arc string `json:"arc"`}但我不知道如何解析像“hello”和“world”這樣的包裝器
1 回答

繁花不似錦
TA貢獻1851條經驗 獲得超4個贊
您需要做的就是構建根映射。
{ ????"hello":{}, ????????"world":{} }
這里的hello
和world
也在地圖內。所以你也需要構建它們。
?var?root?map[string]chapter ?json.Unmarshal(JSONDATA,&root)
- 1 回答
- 0 關注
- 108 瀏覽
添加回答
舉報
0/150
提交
取消