From: Quentin Smith Date: Thu, 26 May 2016 21:53:21 +0000 (-0400) Subject: encoding/json: improve Decode example X-Git-Tag: go1.7beta1~71 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b1894bb5cc781f1c59af727cea07ba4e84181830;p=gostls13.git 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 --- diff --git a/src/encoding/json/example_test.go b/src/encoding/json/example_test.go index 326bdc9540..555eff93c0 100644 --- a/src/encoding/json/example_test.go +++ b/src/encoding/json/example_test.go @@ -143,10 +143,9 @@ func ExampleDecoder_Decode_stream() { } fmt.Printf("%T: %v\n", t, t) - var m Message // while the array contains values for dec.More() { - + var m Message // decode an array value (Message) err := dec.Decode(&m) if err != nil {