Skip to content
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

Added json.NewDecoder example #566

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
)

// We'll use these two structs to demonstrate encoding and
Expand Down Expand Up @@ -121,4 +122,11 @@ func main() {
enc := json.NewEncoder(os.Stdout)
d := map[string]int{"apple": 5, "lettuce": 7}
enc.Encode(d)

// We can also decode JSON directly from `os.Reader`
dec := json.NewDecoder(strings.NewReader(str))
res1 := response2{}
dec.Decode(&res1)
fmt.Println(res1)
fmt.Println(res1.Fruits[1])
}
4 changes: 2 additions & 2 deletions examples/json/json.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
35295476f817fe575619b6168273a29eddd7f545
JOQpRGJWAxR
75a5664321dafe10fa623c187b90f079c5319a3c
jR7IEUPQF8T
24 changes: 20 additions & 4 deletions public/json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading