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
  • 相关阅读:
    java-String类
    多线程的细节
    java-多线程的练习----妖,等待唤醒,代码重构,lock到condition
    javascript函数的声明和调用
    表单
    java-多线程的入门_进阶总结
    uboot命令
    u-boot移植 III
    u-boot移植 II
    汇编词典
  • 原文地址:https://www.cnblogs.com/gagaAurora/p/13627669.html
Copyright © 2011-2022 走看看