Bson & Json Bytes Convert
go get github.com/everfore/bconv
go get labix.org/v2/mgo/bson
json represents for interface{}, for instance struct, map, slice.
bson represents for bson.M, actually which is a map[string]interface{}.
json to bson, using bson.Marshal
bson to json, using json.Marshal
Well, jsonbytes do not equal bsonbytes. They are different []byte.
We can not use string(bsonbytes) as string.
var testBson = &bson.M{
"Name": "Golang",
}
b := NewBson(testBson)
type Lang struct {
Name string
}
var testJson = &Lang{
Name: "Golang ?",
}
j := NewJson(testJson)
b := NewBson(testBson)
bbbs := b.BBytes()
t.Log(bbbs)
bjbs := b.JBytes()
t.Log(bjbs)
bj := b.Json()
t.Log(bj)
j := NewJson(testJson)
jbbs := j.BBytes()
t.Log(jbbs)
jjbs := j.JBytes()
t.Log(jjbs)
jb := j.Bson()
t.Log(jb)
type Java struct {
Name string
}
var java Java
-
Json Conv
err := j.Conv(&java)
err := b.Json().Conv(&java)
-
Bson Conv
err := j.Bson().Conv(&java)
err := b.Conv(&java)