golang json解析出现值为空
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json

·
我是通过beego框架,将请求过来的json进行解析,并将值保存在结构体中
--------------------1----------------------------------
request := UpdateCommentRequestData{}
req := common.Request{Data: request}
err := json.Unmarshal(controller.Ctx.Input.RequestBody, &req)
---------------------------------------------
其中 UpdateCommentRequestData的结构是这样的
type UpdateCommentRequestData struct {
Id []string `json:"id"`
}
common.request的结构是这样的
type Request struct {
UserId uint64 `json:"userId,string"`
Data interface{} `json:"data"`
}
在1中的代码里面,Data字段传的是request的值,是值的拷贝,也就是说,json解析后的数据并不是赋值到reques中,所以使用request.Id并不会取到值,
如果将代码改成这样,再使用request.Id就可以取到值了
req := common.Request{Data: request},




适用于现代 C++ 的 JSON。
最近提交(Master分支:5 个月前 )
34665ae6
binary -> binary_t
Signed-off-by: Robert Chisholm <robert.chisholm@sheffield.ac.uk> 21 天前
f3dc4684
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.9 to 3.28.10.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0...b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d)
---
updated-dependencies:
- dependency-name: github/codeql-action
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 28 天前
更多推荐
所有评论(0)