Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 662 Bytes

README.md

File metadata and controls

45 lines (31 loc) · 662 Bytes

go-json

Json Selector in Golang for Easier Use.

go-json

document

中文

Install

go get -u github.com/lizongying/go-json@latest

Usage

package main

import (
	"fmt"
	"github.com/lizongying/go-json/gjson"
)

func main() {
	html := `{"name":{"first":"Janet","last":"Prichard"},"age":47, "a": [2,3]}`
	s, _ := gjson.NewSelectorFromStr(html)

	i := s.One(`age`).Int()
	//47
	fmt.Printf("%+v\n", i)

	u64 := s.One(`age`).Int64()
	//47
	fmt.Printf("%+v\n", u64)

	m := s.Many(`a`)
	n := m[0].Float64()
	//2
	fmt.Println(n)
}