Go 的 JSON 开发包 Jason

码农软件 · 软件分类 · JSON/BSON开发包 · 2019-03-31 11:12:25

软件介绍

Jason 是一个 Go 语言用来处理 JSON 文档的开发包。Jason 的强项是解析 JSON 而不是生成 JSON。

示例代码:

root, err := jason.NewFromReader(res.Body)

root.Get("name").String()
root.Get("age").Number()
root.Get("verified").Boolean()
root.Get("education").Object()
root.Get("friends").Array()

//读取嵌套内容
root.Get("person", "name").String()
root.Get("person", "age").Number()
root.Get("person", "verified").Boolean()
root.Get("person", "education").Object()
root.Get("person", "friends").Array()

//判断数值是否存在
root.Has("person", "name")
root.Get("person", "name").Exists()

//数值校验
root.Get("name").IsString()
root.Get("age").IsNumber()
root.Get("verified").IsBoolean()
root.Get("education").IsObject()
root.Get("friends").IsArray()
root.Get("friends").IsNull()

//循环
for _, friend := range person.Get("friends").Array() {
  name := friend.Get("name").String()
  age := friend.Get("age").Number()
}

完整例子:

package main

import (
  "github.com/antonholmquist/jason"
  "log"
)

func main() {

  exampleJSON := `{
    "name": "Walter White",

    "age": 51,
    "children": [
      "junior",
      "holly"
    ],
    "other": {
      "occupation": "chemist",
      "years": 23
    }
  }j, _ := jason.NewObjectFromBytes([]byte(exampleJSON))  log.Println("name:", j.Get("name").String())
  log.Println("age:", j.Get("age").Number())
  log.Println("occupation:", j.Get("other", "occupation").String())
  log.Println("years:", j.Get("other", "years").Number())
  for i, child := range j.Get("children").Array() {
    log.Printf("child %d: %s", i, child.String())
  }
}

本文地址:https://www.codercto.com/soft/d/2544.html

智能革命

智能革命

李彦宏 等 / 中信出版集团 / 2017-5-1 / 68.00元

人类历史上的历次技术革命,都带来了人类感知和认知能力的不断提升,从而使人类知道更多,做到更多,体验更多。以此为标准,李彦宏在本书中将人工智能定义为堪比任何一次技术革命的伟大变革,并且明确提出,在技术与人的关系上,智能革命不同于前几次技术革命,不是人去适应机器,而是机器主动来学习和适应人类,并同人类一起学习和创新这个世界。“人工智能”正式写入2017年政府工作报告,折射出未来人工智能产业在我国经济发......一起来看看 《智能革命》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器