From d7c0bc86516f33cd10d2694d7960cdea5005aff5 Mon Sep 17 00:00:00 2001 From: Emir Pasic Date: Tue, 12 Apr 2022 22:37:06 +0200 Subject: [PATCH] Update documentation on JSON serialization with the new json/encoding interface implementation --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fa67f21..44b5f84 100644 --- a/README.md +++ b/README.md @@ -1402,10 +1402,12 @@ func main() { Populates the container with elements from the input JSON representation. Typical usage for key-value structures: + ```go package main import ( + "encoding/json" "fmt" "github.com/emirpasic/gods/maps/hashmap" ) @@ -1413,8 +1415,8 @@ import ( func main() { hm := hashmap.New() - json := []byte(`{"a":"1","b":"2"}`) - err := hm.FromJSON(json) + bytes := []byte(`{"a":"1","b":"2"}`) + err := json.Unmarshal(bytes, &hm) // Same as "hm.FromJSON(bytes)" if err != nil { fmt.Println(err) } @@ -1423,10 +1425,12 @@ func main() { ``` Typical usage for value-only structures: + ```go package main import ( + "encoding/json" "fmt" "github.com/emirpasic/gods/lists/arraylist" ) @@ -1434,8 +1438,8 @@ import ( func main() { list := arraylist.New() - json := []byte(`["a","b"]`) - err := list.FromJSON(json) + bytes := []byte(`["a","b"]`) + err := json.Unmarshal(bytes, &list) // Same as "list.FromJSON(bytes)" if err != nil { fmt.Println(err) }