考慮以下🎜>
{ "1001":{ "level":10, "monster-id":1001, "skill-level":1, "aimer-id":301 }, "1002":{ "level":12, "monster-id":1002, "skill-level":1, "aimer-id":302 }, "1003":{ "level":16, "monster-id":1003, "skill-level":2, "aimer-id":303 } }
type Monster struct { MonsterId int32 Level int32 SkillLevel int32 AimerId int32 }
type MonsterCollection struct { Pool map[string]Monster }
func (mc *MonsterCollection) FromJson(jsonStr string) error { var data *map[string]Monster b := []byte(jsonStr) return json.Unmarshal(b, &data) }
type Monster struct { MonsterId int32 `json:"monster-id"` Level int32 `json:"level"` SkillLevel int32 `json:"skill-level"` AimerId int32 `json:"aimer-id"` }
mc := new(MonsterCollection) err := mc.FromJson(jsonStr)
for id, monster := range mc.Pool { fmt.Println(id, monster) }
以上是如何在 Go 中將巢狀 JSON 解組到物件數組中?的詳細內容。更多資訊請關注PHP中文網其他相關文章!