我想使用Golang将我的地图数据放到另一个地图数据中。但是它具有结构类型。
这是我的代码。
birth := make(map[string]interface{})
birth["docType"] = "registerBirth"
birth["agencyCd"] = string(args[0])
birth["birthYmd"] = string(args[1])
birth["lsTypeNm"] = string(args[2])
birth["monthDiff"] = string(args[3])
birth["nationNm"] = string(args[4])
birth["sexNm"] = string(args[5])
birth["regType"] = string(args[9])
birth["regYmd"] = string(args[10])
我想将此地图数据放入另一个地图,但我想使用结构类型。
cattle := make(map[string]interface{})
cattle["docType"] = "information"
cattle["birthInfo"] = struct {
birth map[string]interface{}
}{
birth,
}
但是,当我获取数据时。它会这样显示。
{"birthInfo":{},"docType":"information"}
这是我想要的例子。
"birthInfo": {
"birthYmd": "2018-07-25",
"cattleNo": "cow001",
"docType": "registerBirth",
"farmNo": "farm001",
"flatEartagNo": "eartag123123",
"lsTypeNm": "황소",
"monthDiff": "2018-07",
"nationNm": "austria",
"regType": "직접",
"regYmd": "20185-07-25",
"sexNm": "M"
},
"docType": "information",
...
谢谢。
答案 0 :(得分:0)
问题出在这部分代码
Failures:
1) Verification of BS_057_LockDN Verify success response for BS_057_LockDN
Message:
TypeError: Cannot read property 'MsgType_T' of undefined
Stack:
at <Jasmine>
at Request._callback (F:\johny\node_from_home\spec\BS_057_LockDN.spec.js:44:32)
at Request.self.callback (F:\johny\node_from_home\node_modules\request\request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (F:\johny\node_from_home\node_modules\request\request.js:1157:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (F:\johny\node_from_home\node_modules\request\request.js:1079:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
Message:
Failed: Cannot read property 'MsgType_T' of undefined
Stack:
at <Jasmine>
at Request._callback (F:\johny\node_from_home\spec\BS_057_LockDN.spec.js:44:32)
at Request.self.callback (F:\johny\node_from_home\node_modules\request\request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (F:\johny\node_from_home\node_modules\request\request.js:1157:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (F:\johny\node_from_home\node_modules\request\request.js:1079:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
1 spec, 1 failure
Finished in 60.348 seconds
Randomized with seed 13965 (jasmine --random=true --seed=13965)
json包只能封送导出的值(公共/以大写字母开头)。
将代码块更改为此,它将起作用:
cattle["birthInfo"] = struct {
birth map[string]interface{}
}{
birth,
}
具有导出的字段名称的可运行示例: