Skip to content

Instantly share code, notes, and snippets.

@rtt
Created September 28, 2012 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtt/3800616 to your computer and use it in GitHub Desktop.
Save rtt/3800616 to your computer and use it in GitHub Desktop.
func DecodeJsonToDocCollection (blob []byte) *DocumentCollection {
var cont interface{}
err := json.Unmarshal(blob, &cont)
if err != nil {
fmt.Println("Decode error")
}
response := cont.(map[string] interface{})["response"]
hits := int(response.(map[string] interface{})["numFound"].(float64))
docs := response.(map[string] interface{})["docs"].([]interface{})
coll := DocumentCollection{}
coll.Hits = hits
ds := make([]Document, hits)
for i := 0; i < hits; i++ {
docs[i] = Document{docs[i].(map[string] interface{})}
}
coll.Collection = ds
return &coll
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment