Hyperledger fabric 学习笔记: go语言 与 JSON
2017-08-06 22:42
501 查看
1、JSON 介绍
JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式。具体介绍可参考https://zh.wikipedia.org/wiki/JSON
2、JSON 与 Go
Go语言自带的JSON转换库为 encoding/json。
http://golang.org/doc/articles/json_and_go.html,这是官方的一篇博客,介绍的挺详细,不过是英文版的。
3、用处
结构体成员变量 ‘xxxx’ 里面的 json字符串是Go语言的structTag。
structTag:如果希望手动配置结构体的成员和JSON字段的对应关系,可以在定义结构体的时候给成员打标签:
使用omitempty熟悉,如果该字段为nil或0值(数字0,字符串”“,空数组[]等),则打包的JSON结果不会有这个字段。
样例:点击打开链接
4、其他用法
可参考博客:http://blog.csdn.net/tiaotiaoyly/article/details/38942311
JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式。具体介绍可参考https://zh.wikipedia.org/wiki/JSON
2、JSON 与 Go
Go语言自带的JSON转换库为 encoding/json。
http://golang.org/doc/articles/json_and_go.html,这是官方的一篇博客,介绍的挺详细,不过是英文版的。
3、用处
//引用 hyperledger fabric-ca 的go语言代码 type RegistrationRequest struct { // Name is the unique name of the identity Name string `json:"id" help:"Unique name of the identity"` // Type of identity being registered (e.g. "peer, app, user") Type string `json:"type" help:"Type of identity being registered (e.g. 'peer, app, user')"` // Secret is an optional password. If not specified, // a random secret is generated. In both cases, the secret // is returned in the RegistrationResponse. Secret string `json:"secret,omitempty" help:"The enrollment secret for the identity being registered"` // MaxEnrollments is the maximum number of times the secret can // be reused to enroll. MaxEnrollments int `json:"max_enrollments,omitempty" help:"The maximum number of times the secret can be reused to enroll."` // is returned in the response. // The identity's affiliation. // For example, an affiliation of "org1.department1" associates the identity with "department1" in "org1". Affiliation string `json:"affiliation" help:"The identity's affiliation"` // Attr is used to support a single attribute provided through the fabric-ca-client CLI Attr string `help:"Attributes associated with this identity (e.g. hf.Revoker=true)"` // Attributes associated with this identity Attributes []Attribute `json:"attrs,omitempty"` }
结构体成员变量 ‘xxxx’ 里面的 json字符串是Go语言的structTag。
structTag:如果希望手动配置结构体的成员和JSON字段的对应关系,可以在定义结构体的时候给成员打标签:
使用omitempty熟悉,如果该字段为nil或0值(数字0,字符串”“,空数组[]等),则打包的JSON结果不会有这个字段。
样例:点击打开链接
4、其他用法
可参考博客:http://blog.csdn.net/tiaotiaoyly/article/details/38942311
相关文章推荐
- Hyperledger Fabric V1.0 学习笔记(一) Centos 7中的环境搭建
- Go语言并发与并行学习笔记(一)
- Go语言学习笔记(4)复合类型
- Go语言并发与并行学习笔记(一)
- Go语言并发与并行学习笔记(一)
- 八、Go语言包之strings--go语言学习笔记
- Go语言学习笔记(二) [变量、类型、关键字]
- Go语言并发与并行学习笔记(二)
- Go语言学习笔记二: 变量
- Go语言学习笔记7
- GO语言学习笔记3(函数接口并发)
- Go语言学习笔记--类型、指针、面向对象
- go语言学习笔记(8) 流程控制
- GO语言学习笔记-170109
- Go语言学习笔记 - 简介
- Go语言并发与并行学习笔记(二)
- Go语言学习笔记(六) [包]
- GO1.6语言学习笔记3-工具篇(SublimeText 3+GoSublime组合)
- Go/Golang 语言学习笔记总结
- go语言学习笔记之并发编程