mirror of https://github.com/tidwall/gjson.git
Compare commits
3 Commits
99f7224c3b
...
e3395843c8
Author | SHA1 | Date |
---|---|---|
Michel Couillard | e3395843c8 | |
tidwall | c2bc5a409a | |
Michel Couillard | b877ac2b1c |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
11
README.md
11
README.md
|
@ -1,7 +1,9 @@
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img
|
<picture>
|
||||||
src="logo.png"
|
<source media="(prefers-color-scheme: dark)" srcset="/.github/images/logo-dark.png">
|
||||||
width="240" height="78" border="0" alt="GJSON">
|
<source media="(prefers-color-scheme: light)" srcset="/.github/images/logo-light.png">
|
||||||
|
<img src="/.github/images/logo-light.png" width="240" alt="GJSON" >
|
||||||
|
</picture>
|
||||||
<br>
|
<br>
|
||||||
<a href="https://godoc.org/github.com/tidwall/gjson"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a>
|
<a href="https://godoc.org/github.com/tidwall/gjson"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a>
|
||||||
<a href="https://tidwall.com/gjson-play"><img src="https://img.shields.io/badge/%F0%9F%8F%90-playground-9900cc.svg?style=flat-square" alt="GJSON Playground"></a>
|
<a href="https://tidwall.com/gjson-play"><img src="https://img.shields.io/badge/%F0%9F%8F%90-playground-9900cc.svg?style=flat-square" alt="GJSON Playground"></a>
|
||||||
|
@ -338,12 +340,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