mirror of https://github.com/tidwall/gjson.git
Compare commits
2 Commits
e3395843c8
...
99f7224c3b
Author | SHA1 | Date |
---|---|---|
Michel Couillard | 99f7224c3b | |
Michel Couillard | b877ac2b1c |
|
@ -338,12 +338,13 @@ println(name.String()) // prints "Elliotte"
|
||||||
|
|
||||||
The `ForEach` function allows for quickly iterating through an object or array.
|
The `ForEach` function allows for quickly iterating through an object or array.
|
||||||
The key and value are passed to the iterator function for objects.
|
The key and value are passed to the iterator function for objects.
|
||||||
Only the value is passed for arrays.
|
With an array the key is an index and the value is passed.
|
||||||
Returning `false` from an iterator will stop iteration.
|
Returning `false` from an iterator will stop iteration.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
result := gjson.Get(json, "programmers")
|
result := gjson.Get(json, "programmers")
|
||||||
result.ForEach(func(key, value gjson.Result) bool {
|
result.ForEach(func(key, value gjson.Result) bool {
|
||||||
|
println(key.Int()) // index of the array
|
||||||
println(value.String())
|
println(value.String())
|
||||||
return true // keep iterating
|
return true // keep iterating
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue