mirror of
https://github.com/json-iterator/go.git
synced 2025-01-23 18:54:21 +02:00
update README
This commit is contained in:
parent
6cd6ed2681
commit
d0f45c663f
35
README.md
35
README.md
@ -12,9 +12,9 @@ Here is a quick show off, for more complete report you can checkout the full [be
|
|||||||
|
|
||||||
![go-medium](http://jsoniter.com/benchmarks/go-medium.png)
|
![go-medium](http://jsoniter.com/benchmarks/go-medium.png)
|
||||||
|
|
||||||
# 1 Minute Tutorial
|
# Bind-API is the best
|
||||||
|
|
||||||
Given this JSON document `[0,1,2,3]`
|
Bind-api should always be the first choice. Given this JSON document `[0,1,2,3]`
|
||||||
|
|
||||||
Parse with Go bind-api
|
Parse with Go bind-api
|
||||||
|
|
||||||
@ -26,27 +26,36 @@ iter.Read(&val)
|
|||||||
fmt.Println(val[3])
|
fmt.Println(val[3])
|
||||||
```
|
```
|
||||||
|
|
||||||
Parse with Go any-api
|
# Iterator-API for quick extraction
|
||||||
|
|
||||||
```go
|
When you do not need to get all the data back, just extract some.
|
||||||
import "github.com/json-iterator/go"
|
|
||||||
iter := jsoniter.ParseString(`[0,1,2,3]`)
|
|
||||||
val := iter.ReadAny()
|
|
||||||
fmt.Println(val.Get(3))
|
|
||||||
```
|
|
||||||
|
|
||||||
Parse with Go iterator-api
|
Parse with Go iterator-api
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import "github.com/json-iterator/go"
|
import "github.com/json-iterator/go"
|
||||||
iter := ParseString(`[0,1,2,3]`)
|
iter := ParseString(`[0, [1, 2], [3, 4], 5]`)
|
||||||
total := 0
|
count := 0
|
||||||
for iter.ReadArray() {
|
for iter.ReadArray() {
|
||||||
total += iter.ReadInt()
|
iter.skip()
|
||||||
|
count++
|
||||||
}
|
}
|
||||||
fmt.Println(total)
|
fmt.Println(count) // 4
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Any-API for maximum flexibility
|
||||||
|
|
||||||
|
Parse with Go any-api
|
||||||
|
|
||||||
|
```go
|
||||||
|
import "github.com/json-iterator/go"
|
||||||
|
iter := jsoniter.ParseString(`[{"field1":"11","field2":"12"},{"field1":"21","field2":"22"}]`)
|
||||||
|
val := iter.ReadAny()
|
||||||
|
fmt.Println(val.ToInt(1, "field2")) // 22
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice you can extract from nested data structure, and convert any type to the type to you want.
|
||||||
|
|
||||||
# How to get
|
# How to get
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user