mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: improve Decode example
Decoding a JSON message does not touch unspecified or null fields; always use a new underlying struct to prevent old field values from sticking around. Fixes: #14640 Change-Id: Ica78c208ce104e2cdee1d4e92bf58596ea5587c8 Reviewed-on: https://go-review.googlesource.com/23483 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
parent
02bf6b5ef9
commit
b1894bb5cc
1 changed files with 1 additions and 2 deletions
|
|
@ -143,10 +143,9 @@ func ExampleDecoder_Decode_stream() {
|
||||||
}
|
}
|
||||||
fmt.Printf("%T: %v\n", t, t)
|
fmt.Printf("%T: %v\n", t, t)
|
||||||
|
|
||||||
var m Message
|
|
||||||
// while the array contains values
|
// while the array contains values
|
||||||
for dec.More() {
|
for dec.More() {
|
||||||
|
var m Message
|
||||||
// decode an array value (Message)
|
// decode an array value (Message)
|
||||||
err := dec.Decode(&m)
|
err := dec.Decode(&m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue