diff --git a/gjson.go b/gjson.go index 8550a8c..2e16394 100644 --- a/gjson.go +++ b/gjson.go @@ -473,6 +473,9 @@ func Get(json string, path string) Result { // alpha lowercase continue } + if path[i] >= 'A' && path[i] <= 'Z' { + continue + } if path[i] == '.' { // append a new part parts = append(parts, part{wild: wild, key: path[s:i]}) @@ -483,7 +486,7 @@ func Get(json string, path string) Result { s = i + 1 continue } - if (path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= '0' && path[i] <= '9') { + if (path[i] >= '0' && path[i] <= '9') || path[i] == '_' { continue } if path[i] == '*' || path[i] == '?' { @@ -515,7 +518,9 @@ func Get(json string, path string) Result { } continue } else if path[i] == '.' { - parts = append(parts, part{wild: wild, key: string(epart)}) + parts = append(parts, part{ + wild: wild, key: string(epart), + }) if wild { wild = false } diff --git a/gjson_test.go b/gjson_test.go index 15dfa24..634ffe3 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "encoding/json" + "fmt" "io" "math/rand" "strings" @@ -299,6 +300,41 @@ func TestLess(t *testing.T) { assert(t, stringLessInsensitive("124abcde", "125abcde")) } +func TestIssue6(t *testing.T) { + data := `{ + "code": 0, + "msg": "", + "data": { + "sz002024": { + "qfqday": [ + [ + "2014-01-02", + "8.93", + "9.03", + "9.17", + "8.88", + "621143.00" + ], + [ + "2014-01-03", + "9.03", + "9.30", + "9.47", + "8.98", + "1624438.00" + ] + ] + } + } + }` + + var num []string + for _, v := range Get(data, "data.sz002024.qfqday.0").Array() { + num = append(num, v.String()) + } + fmt.Printf("%v\n", num) +} + var exampleJSON = `{ "widget": { "debug": "on",