gjson 是一个 Go 开发
包,提供了非常快速和简单的方式来获得一个
JSON 文档
的值
。此文库的存在是为 BuntDB 项目提供高效的 JSON 索引。
### 安装:
开始使用
GJSON,安装
Go ,并运行
go get:
<pre class="brush:java;toolbar: true; auto-links: false;">$ go get -u github.com/tidwall/gjson</pre>
此操作可恢复文库。
### 性能:
与
[encoding/json](https://golang.org/pkg/encoding/json/)
,
[ffjson](https://github.com/pquerna/ffjson)
,
[EasyJSON](https://github.com/mailru/easyjson)
, 和
[jsonparser](https://github.com/buger/jsonparser) 并列的
GJSON 基准点。
<pre box-sizing:="" font-family:="" liberation="" font-size:="" margin-top:="" margin-bottom:="" font-stretch:="" line-height:="" word-wrap:="" padding:="" overflow:="" background-color:="" border-radius:="" color:="">BenchmarkGJSONGet-8 15000000 333 ns/op 0 B/op 0 allocs/op
BenchmarkGJSONUnmarshalMap-8 900000 4188 ns/op 1920 B/op 26 allocs/op
BenchmarkJSONUnmarshalMap-8 600000 8908 ns/op 3048 B/op 69 allocs/op
BenchmarkJSONUnmarshalStruct-8 600000 9026 ns/op 1832 B/op 69 allocs/op
BenchmarkJSONDecoder-8 300000 14339 ns/op 4224 B/op 184 allocs/op
BenchmarkFFJSONLexer-8 1500000 3156 ns/op 896 B/op 8 allocs/op
BenchmarkEasyJSONLexer-8 3000000 938 ns/op 613 B/op 6 allocs/op
BenchmarkJSONParserGet-8 3000000 442 ns/op 21 B/op 0 allocs/op</pre>
JSON 文档使用:
<pre class="brush:java;toolbar: true; auto-links: false;">{ "widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": 500, "height": 500
}, "image": {
"src": "Images/Sun.png", "hOffset": 250, "vOffset": 250, "alignment": "center"
}, "text": { "data": "Click Here", "size": 36, "": "bold", "vOffset": 100, "alignment": "center", "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
}</pre>
每个操作都
是通过下面的搜索路径之一回转:
<pre class="brush:java;toolbar: true; auto-links: false;">widget.window.name
widget.image.hOffset
widget.text.onMouseU</pre>