Skip to content

Instantly share code, notes, and snippets.

@alena1108
Created February 23, 2016 22:40
Show Gist options
  • Save alena1108/06882fdd03bddfbd4b27 to your computer and use it in GitHub Desktop.
Save alena1108/06882fdd03bddfbd4b27 to your computer and use it in GitHub Desktop.
readData
func (s *Server) parseData(dataStr string, obj interface{}) error {
type Data struct {
Fields interface{} `json:"fields"`
}
data := Data{}
bytes := []byte(dataStr)
if err := json.Unmarshal(bytes, &data); err != nil {
return err
}
fieldsM, err := json.Marshal(data.Fields)
if err != nil {
return err
}
if err = json.Unmarshal(fieldsM, &obj); err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment