https://github.com/m0a/easyjson
easyjson
https://github.com/m0a/easyjson
Last synced: about 1 year ago
JSON representation
easyjson
- Host: GitHub
- URL: https://github.com/m0a/easyjson
- Owner: m0a
- Created: 2014-09-20T12:04:11.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-10-05T22:04:33.000Z (over 9 years ago)
- Last Synced: 2025-03-15T08:46:44.599Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# m0a/easyjson
========
go's easy json access library
## Usage
simple example:
```go
package main
import (
"github.com/m0a/easyjson"
"net/http"
"fmt"
)
func main() {
url := "http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&sensor=false"
resp, err := http.Get(url)
if err != nil {
panic(err)
}
if resp.StatusCode != http.StatusOK {
panic(resp.StatusCode)
}
json,err := easyjson.NewEasyJson(resp.Body)
if err!=nil {
panic("json convert err")
}
//easy access!
json.K("routes",0,"bounds","southwest").PrettyPrint()
//support method chain
json.K("routes").K(0).K("bounds").K("southwest").PrettyPrint()
// if use loop
for k,v:=range json.K("routes").K(0).RangeObjects() {
fmt.Printf("%v:%v\n",k,v)
}
//string value
copyrights,err:=json.K("routes").K(0).K("copyrights").AsString()
if err!=nil {
panic("AsString err")
}
fmt.Printf("copyrights=%s",copyrights)
}
```