修正gjson数据检索问题

This commit is contained in:
John
2018-01-23 15:43:16 +08:00
parent 4e1fbafe9b
commit 8a59aea6a6
3 changed files with 8 additions and 4 deletions

View File

@ -311,6 +311,9 @@ func (j *Json) getPointerByPattern(pattern string) *interface{} {
}
} else {
index = strings.LastIndex(pattern[start:index], ".")
if index != -1 && length > 0 {
index += length + 1
}
}
if start >= index {
break

View File

@ -12,7 +12,7 @@ func Upload(r *ghttp.Request) {
buffer := make([]byte, h.Size)
f.Read(buffer)
gfile.PutBinContents("/tmp/" + fname, buffer)
r.Response.WriteString(fname + " uploaded successly"))
r.Response.WriteString(fname + " uploaded successly")
} else {
r.Response.WriteString(e.Error())
}

View File

@ -7,9 +7,10 @@ import (
)
func main() {
j, _ := gjson.Load("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/frame/config.json")
c, _ := j.ToToml()
fmt.Println(string(c))
j, _ := gjson.Load("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/frame/config.yml")
//c, _ := j.ToToml()
//fmt.Println(j.Get("database.default").([]interface{})[0])
fmt.Println(j.Get("database.default.0"))
return
data :=
`{