Update documentation on JSON serialization with the new json/encoding interface implementation

pull/154/merge
Emir Pasic 2 years ago
parent 9641d19f46
commit d7c0bc8651

@ -1402,10 +1402,12 @@ func main() {
Populates the container with elements from the input JSON representation. Populates the container with elements from the input JSON representation.
Typical usage for key-value structures: Typical usage for key-value structures:
```go ```go
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/emirpasic/gods/maps/hashmap" "github.com/emirpasic/gods/maps/hashmap"
) )
@ -1413,8 +1415,8 @@ import (
func main() { func main() {
hm := hashmap.New() hm := hashmap.New()
json := []byte(`{"a":"1","b":"2"}`) bytes := []byte(`{"a":"1","b":"2"}`)
err := hm.FromJSON(json) err := json.Unmarshal(bytes, &hm) // Same as "hm.FromJSON(bytes)"
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@ -1423,10 +1425,12 @@ func main() {
``` ```
Typical usage for value-only structures: Typical usage for value-only structures:
```go ```go
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/emirpasic/gods/lists/arraylist" "github.com/emirpasic/gods/lists/arraylist"
) )
@ -1434,8 +1438,8 @@ import (
func main() { func main() {
list := arraylist.New() list := arraylist.New()
json := []byte(`["a","b"]`) bytes := []byte(`["a","b"]`)
err := list.FromJSON(json) err := json.Unmarshal(bytes, &list) // Same as "list.FromJSON(bytes)"
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }

Loading…
Cancel
Save