我尝试将node.js代码转换为golang代码。这是我的示例JSON。{ "result": { "birthInfo": { "birthYmd": "2018-07-25", "cattleNo": "cow001", "docType": "registerBirth", "lsTypeNm": "redbull", "monthDiff": "2018-07", "nationNm": "japan", "regType": "directly", "regYmd": "2018-07-25", "sexNm": "farm001" }, "breed": { "dead": { "deadCd": "deadcd20180725", "deadYmd": "2018-07-25", "docType": "reportDeCattle" }, "earTag": { "docType": "reattachEartag", "flatEartagNo": "eartag206015", "rfidNo": "rfid234234" } } }} 使用node.js时,很容易获得或访问json数据,就像这样。let cowbytes = await stub.getState("cow001");var cowInfo = JSON.parse(cowbytes);var eartag = { docType: 'reattachEartag', flatEartagNo: "eartag206015", rfidNo: "rfid234234",};if (cowInfo.breed) { cowInfo.breed['earTag'] = eartag;} else { cowInfo.breed = { earTag: eartag };}await stub.putState(args[0], Buffer.from(JSON.stringify(cowInfo)));这是我对node.js代码进行基准测试的golang代码。尽管我的golang文件可以正常工作,但我认为这不仅很难编写代码,而且性能也很差(重复的元组和非元组)。如何在Golang中轻松控制JSON类型。有人有主意吗?
2 回答
- 2 回答
- 0 关注
- 303 浏览
添加回答
举报
0/150
提交
取消