Hi there...
I'm completely new to Go, and my first project is something that grabs
a bunch of data from a MongoDB database and converts the objects to
JSON strings. I've got this so far:
for cursor.HasNext() {
var m mongo.M
err := cursor.Next(&m)
if err != nil { log.Fatal(err) }
log.Print(m)
jsonStr, err := json.Marshal(m)
if err != nil { log.Fatal(err) }
log.Print(jsonStr)
}
The program bails on the first time through this loop, and prints
this:
2011/06/05 15:34:59 map[top:37 name: height:120 width:186 Template2_ID:
4c4ea54697a5679a5cf8f61a Template2Sector_ID:4c4f9e45f6440c3da02894ed
left:414 _id:4c4f9e45148c00c4106e907e]
2011/06/05 15:34:59 json: invalid UTF-8 in string: "LO\x9eE\xf6D\f=
\xa0(\x94\xed"
The data is coming from MongoDB and it stores data as UTF-8 so I don't
see how it could be invalid. I've checked that exact record using
other MongoDB tools and it seems to be fine. If it helps, I'm using
this driver:
http://garyburd.github.com/go-mongo
Cheers,
Matt