| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package main
- //
- //import (
- // "fmt"
- //
- // "github.com/tidwall/gjson"
- //)
- //
- //var json = `
- //{
- // "name": {"first": "Tom", "last": "Anderson"},
- // "age":37,
- // "weight": 4.2,
- // "foot": nil,
- // "male": true,
- // "children": ["Sara","Alex","Jack"],
- // "fav.movie": "Deer Hunter",
- // "friends": [
- // {"first": "Dale", "last": "Murphy", "age": 44},
- // {"first": "Roger", "last": "Craig", "age": 68},
- // {"first": "Jane", "last": "Murphy", "age": 47}
- // ]
- //}
- //`
- //
- //func main() {
- //
- // value := gjson.Get(json, "xxxxx")
- // println(value.String(), value.Type)
- //
- // value = gjson.Get(json, "foot")
- // println(value.String(), value.Type)
- //
- // value = gjson.Get(json, "a?e")
- // println(value.String(), value.Type)
- //
- // value = gjson.Get(json, "male")
- // println(value.String(), value.Type)
- //
- // value = gjson.Get(json, "weight")
- // println(value.String(), value.Type)
- //
- // value = gjson.Get(json, "name.last")
- // println(value.Raw, value.Type)
- //
- // value = gjson.Get(json, "name")
- // println(value.String(), value.Type)
- //
- //
- // value = gjson.Get(json, "friends")
- // println(value.String(), value.Type)
- //
- // if gjson.Get(json, "name.la?t").Exists() {
- // println("has a last name")
- // }else{
- // println("has't a last name")
- // }
- //
- // if gjson.Get(json, "name.la?t").Exists() {
- // println("has a last name")
- // }else{
- // println("has't a last name")
- // }
- //
- // m, ok := gjson.Parse(json).Value().(map[string]interface{})
- // if !ok {
- // // not a map
- // }else{
- // fmt.Println( m )
- // }
- //
- //var jsonString = `
- //[
- // {
- // "name": "elgs",
- // "gender": "m",
- // "age": 35,
- // "skills": [
- // "Golang",
- // "Java",
- // "C"
- // ]
- // },
- // {
- // "name": "enny",
- // "gender": "f",
- // "age": 36,
- // "hobby": null,
- // "skills": [
- // "IC",
- // "Electric design",
- // "Verification"
- // ]
- // },
- // {
- // "name": "sam",
- // "gender": "m",
- // "age": 1,
- // "hobby": "dancing",
- // "skills": [
- // "Eating",
- // "Sleeping",
- // "Crawling"
- // ]
- // }
- //]
- //`
- // value = gjson.Get(jsonString, `#[name=="sam"]`)
- // println(value.String(), value.Type)
- //
- //}
|