From d0f45c663f42b8b1635b3bf0c439e5caa9760fe2 Mon Sep 17 00:00:00 2001 From: Tao Wen Date: Thu, 15 Dec 2016 23:49:56 +0800 Subject: [PATCH] update README --- README.md | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 80e2856..66b4e98 100644 --- a/README.md +++ b/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) -# 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 @@ -26,27 +26,36 @@ iter.Read(&val) fmt.Println(val[3]) ``` -Parse with Go any-api +# Iterator-API for quick extraction -```go -import "github.com/json-iterator/go" -iter := jsoniter.ParseString(`[0,1,2,3]`) -val := iter.ReadAny() -fmt.Println(val.Get(3)) -``` +When you do not need to get all the data back, just extract some. Parse with Go iterator-api ```go import "github.com/json-iterator/go" -iter := ParseString(`[0,1,2,3]`) -total := 0 +iter := ParseString(`[0, [1, 2], [3, 4], 5]`) +count := 0 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 ```