diff options
author | Sergey 'SnakE' Gromov <snake.scaly@gmail.com> | 2009-11-30 13:55:09 -0800 |
---|---|---|
committer | Sergey 'SnakE' Gromov <snake.scaly@gmail.com> | 2009-11-30 13:55:09 -0800 |
commit | 7ea3f61ab343b1115d561dd051879fccbb35df20 (patch) | |
tree | 61f69f892695ac35bc78ad8c4f60739836ddc0b9 /src/pkg/expvar | |
parent | 2b64b6a9acdf85fca4a457d4364fa468d0ad2ffe (diff) | |
download | golang-7ea3f61ab343b1115d561dd051879fccbb35df20.tar.gz |
json: Decode into native Go data structures
This patch adds an ability to convert JSON-encoded data into
a hierarchy of Go's native data types.
R=rsc
CC=golang-dev
http://codereview.appspot.com/161060
Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/pkg/expvar')
-rw-r--r-- | src/pkg/expvar/expvar_test.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/pkg/expvar/expvar_test.go b/src/pkg/expvar/expvar_test.go index cbbb2cbef..e64bdc2cc 100644 --- a/src/pkg/expvar/expvar_test.go +++ b/src/pkg/expvar/expvar_test.go @@ -61,18 +61,20 @@ func TestMapCounter(t *testing.T) { // colours.String() should be '{"red":3, "blue":4}', // though the order of red and blue could vary. s := colours.String(); - j, ok, errtok := json.StringToJson(s); - if !ok { - t.Errorf("colours.String() isn't valid JSON: %v", errtok) + j, err := json.Decode(s); + if err != nil { + t.Errorf("colours.String() isn't valid JSON: %v", err) } - if j.Kind() != json.MapKind { + m, ok := j.(map[string]interface{}); + if !ok { t.Error("colours.String() didn't produce a map.") } - red := j.Get("red"); - if red.Kind() != json.NumberKind { - t.Error("red.Kind() is not a NumberKind.") + red := m["red"]; + x, ok := red.(float64); + if !ok { + t.Error("red.Kind() is not a number.") } - if x := red.Number(); x != 3 { + if x != 3 { t.Error("red = %v, want 3", x) } } |