forked from mirror/gjson
added Index field
This commit is contained in:
parent
2dec1c4e7b
commit
800ce5e927
|
@ -106,6 +106,7 @@ result.Str // holds the string
|
||||||
result.Num // holds the float64 number
|
result.Num // holds the float64 number
|
||||||
result.Raw // holds the raw json
|
result.Raw // holds the raw json
|
||||||
result.Multi // holds nested array values
|
result.Multi // holds nested array values
|
||||||
|
result.Index // index of raw value in original json, zero means index unknown
|
||||||
```
|
```
|
||||||
|
|
||||||
There are a variety of handy functions that work on a result:
|
There are a variety of handy functions that work on a result:
|
||||||
|
|
10
gjson.go
10
gjson.go
|
@ -37,6 +37,8 @@ type Result struct {
|
||||||
Str string
|
Str string
|
||||||
// Num is the json number
|
// Num is the json number
|
||||||
Num float64
|
Num float64
|
||||||
|
// Index of raw value in original json, zero means index unknown
|
||||||
|
Index int
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a string representation of the value.
|
// String returns a string representation of the value.
|
||||||
|
@ -1131,6 +1133,14 @@ func Get(json, path string) Result {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(c.value.Raw) > 0 {
|
||||||
|
jhdr := *(*reflect.StringHeader)(unsafe.Pointer(&json))
|
||||||
|
rhdr := *(*reflect.StringHeader)(unsafe.Pointer(&(c.value.Raw)))
|
||||||
|
c.value.Index = int(rhdr.Data - jhdr.Data)
|
||||||
|
if c.value.Index < 0 || c.value.Index >= len(json) {
|
||||||
|
c.value.Index = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue