Jason 基于 Go 的 JSON 开发包开源项目

我要开发同款
匿名用户2014年12月03日
107阅读

技术信息

开源地址
https://github.com/antonholmquist/jason
授权协议
MIT

作品详情

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

示例代码:

root, err := jaso.NewFromReader(res.Body)root.Get("ame").Strig()root.Get("age").Number()root.Get("verified").Boolea()root.Get("educatio").Object()root.Get("frieds").Array()//读取嵌套内容root.Get("perso", "ame").Strig()root.Get("perso", "age").Number()root.Get("perso", "verified").Boolea()root.Get("perso", "educatio").Object()root.Get("perso", "frieds").Array()//判断数值是否存在root.Has("perso", "ame")root.Get("perso", "ame").Exists()//数值校验root.Get("ame").IsStrig()root.Get("age").IsNumber()root.Get("verified").IsBoolea()root.Get("educatio").IsObject()root.Get("frieds").IsArray()root.Get("frieds").IsNull()//循环for _, fried := rage perso.Get("frieds").Array() {  ame := fried.Get("ame").Strig()  age := fried.Get("age").Number()}

完整例子:

package maiimport (  "github.com/atoholmquist/jaso"  "log")fuc mai() {  exampleJSON := `{    "ame": "Walter White",    "age": 51,    "childre": [      "juior",      "holly"    ],    "other": {      "occupatio": "chemist",      "years": 23    }  }j, _ := jaso.NewObjectFromBytes([]byte(exampleJSON))  log.Pritl("ame:", j.Get("ame").Strig())  log.Pritl("age:", j.Get("age").Number())  log.Pritl("occupatio:", j.Get("other", "occupatio").Strig())  log.Pritl("years:", j.Get("other", "years").Number())  for i, child := rage j.Get("childre").Array() {    log.Pritf("child %d: %s", i, child.Strig())  }}

功能介绍

Jason 是一个 Go 语言用来处理 JSON 文档的开发包。Jason 的强项是解析 JSON 而不是生成 JSON。 示例代码:
root, err := jason.NewFromR...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论