Skip to content

Instantly share code, notes, and snippets.

@0rka
Created January 28, 2018 11:30
Show Gist options
  • Save 0rka/c56e0dc5ef21169a44527c9f4f78afd7 to your computer and use it in GitHub Desktop.
Save 0rka/c56e0dc5ef21169a44527c9f4f78afd7 to your computer and use it in GitHub Desktop.
UnmarshalJSON
func (p *Playables) UnmarshalJSON(b []byte) error {
var LibraryFields map[string]*json.RawMessage
if err := json.Unmarshal(b, &LibraryFields); err != nil {
return err
}
for LFKey, LFValue := range LibraryFields {
if LFKey == "movies" {
var LibraryMovies []*json.RawMessage
if err := json.Unmarshal(*LFValue, &LibraryMovies); err != nil {
return err
}
for _, LibraryMovie := range LibraryMovies {
var movie Movie
if err := json.Unmarshal(*LibraryMovie, &movie); err != nil {
return err
}
*p = append(*p, &movie)
}
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment