-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ToJSON problem #132
Comments
Can you please also add json MarshalIndent method to it. |
result string: reverse:
panic: interface conversion: interface {} is map[string]interface {}, not *hashmap.Map |
GoDS does not unmarshal nested data structures at the moment. This could be solved by avoiding golang's json encode/decode interfaces and writing our own GoDS marshaler as discussed in #171 (comment) So I will close this issue and leave the other open to remind us of implementing this custom JSON umarshaller that will unmarshal JSON to GoDS data structures even in nested situations. |
@qianqianyeye import (
"fmt"
"github.com/emirpasic/gods/maps/linkedhashmap"
)
// LinkedHashMapExample to demonstrate basic usage of LinkedHashMapExample
func main() {
m := linkedhashmap.New()
m1 := linkedhashmap.New()
c := map[string]interface{}{"S": "sss", "A": "dddd"}
m1.Put("c", c)
m.Put("b", "aaaa")
m.Put("a", "aaaa")
m.Put("c", m1)
mb, err := m.ToJSON()
if err != nil {
fmt.Println(err)
}
fmt.Println(string(mb))
} Output {
"b": "aaaa",
"a": "aaaa",
"c": {
"c": {
"A": "dddd",
"S": "sss"
}
}
} As far as I can see,this looks as expected? |
m := linkedhashmap.New() m1:= linkedhashmap.New() c :=t{S:"sss",A:"dddd"} m1.Put("c",c) m.Put("b","aaaa") m.Put("a","aaaa") m.Put("c",m1) mb,err:=m.ToJSON() if err != nil { fmt.Println(err) } fmt.Println(string(mb))
linkedhashmap contain linkedhashmap, toJSON result is ni(Code above mb inside c is nil)l,I added some code in this func
`// ToJSON outputs the JSON representation of map.
func (m *Map) ToJSON() ([]byte, error) {
var b []byte
buf := bytes.NewBuffer(b)
}`
The text was updated successfully, but these errors were encountered: