Tweak JSON example of unmarshalling a float
The current example shows `json.Unmarshal` on an array of bytes, including `num:6.0`. In the output however this comes out as `6`. Even in the casting to `float64`, it comes out as `6`. This can be confusion because it looks like a simple `int`. By adding an arbitray `.13` you see it's a float.
This commit is contained in:
@@ -69,7 +69,7 @@ func main() {
|
||||
// Now let's look at decoding JSON data into Go
|
||||
// values. Here's an example for a generic data
|
||||
// structure.
|
||||
byt := []byte(`{"num":6.0,"strs":["a","b"]}`)
|
||||
byt := []byte(`{"num":6.13,"strs":["a","b"]}`)
|
||||
|
||||
// We need to provide a variable where the JSON
|
||||
// package can put the decoded data. This
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
12f985bb444e2bd6d72ea52a24ebc5f4f82c5b9b
|
||||
4L2wMVv7tW
|
||||
9a3d67892b3930bceb1167b59d4d4f5527dadefc
|
||||
scgxBwACYx
|
||||
|
||||
@@ -7,8 +7,8 @@ true
|
||||
{"apple":5,"lettuce":7}
|
||||
{"Page":1,"Fruits":["apple","peach","pear"]}
|
||||
{"page":1,"fruits":["apple","peach","pear"]}
|
||||
map[num:6 strs:[a b]]
|
||||
6
|
||||
map[num:6.13 strs:[a b]]
|
||||
6.13
|
||||
a
|
||||
&{1 [apple peach]}
|
||||
apple
|
||||
|
||||
Reference in New Issue
Block a user