@@ -12,40 +12,49 @@ Here is a quick show off, for more complete report you can checkout the full [be
12
12
13
13
![ java1] ( http://jsoniter.com/benchmarks/java1.png )
14
14
15
- # 1 Minute Tutorial
15
+ # Bind-API is the best
16
16
17
- Given this JSON document ` [0,1,2,3] `
17
+ Bind-api should always be the first choice. Given this JSON document ` [0,1,2,3] `
18
18
19
19
Parse with Java bind-api
20
20
21
21
``` java
22
- import com.jsoniter.JsonIterator ;
22
+ import com.jsoniter.Jsoniter ;
23
23
Jsoniter iter = Jsoniter . parse(" [0,1,2,3]" );
24
24
int [] val = iter. read(int []. class);
25
25
System . out. println(val[3 ]);
26
26
```
27
27
28
- Parse with Java any-api
28
+ # Iterator-API for quick extraction
29
29
30
- ``` java
31
- import com.jsoniter.JsonIterator ;
32
- Jsoniter iter = Jsoniter . parse(" [0,1,2,3]" );
33
- Any val = iter. readAny();
34
- System . out. println(any. get(3 ));
35
- ```
30
+ When you do not need to get all the data back, just extract some.
36
31
37
32
Parse with Java iterator-api
38
33
39
34
``` java
40
- import com.jsoniter.JsonIterator ;
41
- Jsoniter iter = Jsoniter . parse(" [0,1,2,3 ]" );
42
- int total = 0 ;
35
+ import com.jsoniter.Jsoniter ;
36
+ Jsoniter iter = Jsoniter . parse(" [0, [1, 2], [3, 4], 5 ]" );
37
+ int count = 0 ;
43
38
while (iter. readArray()) {
44
- total += iter. readInt();
39
+ iter. skip();
40
+ count++ ;
45
41
}
46
- System . out. println(total);
42
+ System . out. println(count); // 4
43
+ ```
44
+
45
+ # Any-API for maximum flexibility
46
+
47
+ Parse with Java any-api
48
+
49
+ ``` java
50
+ import com.jsoniter.Jsoniter ;
51
+ Jsoniter iter = Jsoniter . parse(" [{'field1':'11','field2':'12'},{'field1':'21','field2':'22'}]" . replace(' \' ' , ' "' ));
52
+ Any val = iter. readAny();
53
+ System . out. println(val. toInt(1 , " field2" )); // 22
47
54
```
48
55
56
+ Notice you can extract from nested data structure, and convert any type to the type to you want.
57
+
49
58
# How to get
50
59
51
60
```
0 commit comments