zoukankan      html  css  js  c++  java
  • github.com/tidwall/gjson包

    $ go get github.com/tidwall/gjson

    操作

    package main
    
    const json = `
    {
      "name":{"first":"gaga", "小明": "frauk"},
      "age": 18,
      "children": ["xiaohua", "jiajia", "Jayjay],
      "fav.movie": "Dear haha",
      "friends": [
        {"first": "Dale", "last":"Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
        {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
        {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
      ]
    }
    `
    
    func main() {
      fmt.Println("last name:", gjson.Get(json, "name.last"))
      fmt.Println("age:", gjson.Get(json, "age"))
      fmt.Println("children:", gjson.Get(json, "children"))
      fmt.Println("children count:", gjson.Get(json, "children.#"))
      fmt.Println("second child:", gjson.Get(json, "children.1"))
      fmt.Println("third child*:", gjson.Get(json, "child*.2"))
      fmt.Println("first c?ild:", gjson.Get(json, "c?ildren.0"))
      fmt.Println("fav.moive", gjson.Get(json, `fav.moive`))
      fmt.Println("first name of friends:", gjson.Get(json, "friends.#.first"))
      fmt.Println("last name of second friend:", gjson.Get(json, "friends.1.last"))
    }

    结果:

    last name: Anderson
    age: 37
    children: ["Sara", "Alex", "Jack"]
    children count: 3
    second child: Alex
    third child*: Jack
    first c?ild: Sara
    fave.moive 
    first name of friends: ["Dale","Roger","Jane"]
    last name of second friend: Craig
  • 相关阅读:
    Spring 事务全解析
    oracle trigger pl/sql
    reflection
    JAXP(Java API XML Parser)
    log4j扩展后的Appender
    Hibernate sql查询
    tt,mongodb主从启动命令
    4种挂隐藏链接的代码
    Delphi过程函数传递参数的几种方式
    学校Win7 KMS激活服务器已经可以用了
  • 原文地址:https://www.cnblogs.com/gagaAurora/p/13627669.html
Copyright © 2011-2022 走看看