-
-
Save 0rka/c56e0dc5ef21169a44527c9f4f78afd7 to your computer and use it in GitHub Desktop.
UnmarshalJSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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