Hyperledger fabric 学习笔记: go语言 与 JSON
来源:互联网 发布:linux内网穿透知乎 编辑:程序博客网 时间:2024/06/06 04:29
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、用处
//引用 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
阅读全文
0 0
- Hyperledger fabric 学习笔记: go语言 与 JSON
- Hyperledger fabric 学习笔记: fabric v1.0 代码结构
- Hyperledger Fabric Client SDK for Go 下载与配置
- Hyperledger Fabric
- Hyperledger Fabric 项目学习: fabric-ca 依赖包
- Hyperledger Fabric V1.0学习之一---在mac上配置hyperledger fabric
- GO语言学习:JSON处理
- Go语言学习笔记
- Go语言学习笔记
- go语言学习笔记
- Go语言学习笔记
- GO语言学习笔记
- Go语言学习笔记
- GO语言学习笔记
- Go语言学习笔记
- Go语言学习笔记
- Go语言学习笔记
- go语言学习笔记
- Oracle 子查询
- 【目录】Ceph专题文章索引
- JVisualVM监视远程主机Tomcat运行情况
- java函数式编程
- Semaphore 信号量 控制进程
- Hyperledger fabric 学习笔记: go语言 与 JSON
- 杭电1696——基础的二分
- java算法之快速排序
- 每日一题(26)—— 无限循环的几种形式
- JSP工作原理
- 《互联网信贷风险与大数据》读书笔记(六)
- 深入 Generator 函数(三) (Going Async With ES6 Generators)
- Qt 5.7.1 在 msvc2015 方式下的静态编译过程
- 存储函数在 java中的应用