收到的json格式是 {"Hello":{"Name":"client"}}
json中已经有struct的名字了,有什么办法可以根据这个名字方便的把这个json信息解析到对应的struct吗?
对应的struct:
type Hello struct { Name string }
请大佬指点迷津。
有疑问加站长微信联系(非本文作者)

收到的json格式是 {"Hello":{"Name":"client"}}
json中已经有struct的名字了,有什么办法可以根据这个名字方便的把这个json信息解析到对应的struct吗?
对应的struct:
type Hello struct { Name string }
请大佬指点迷津。
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
`单行代码`
type A struct { Hello Hello }
type Hello struct { Name string }
再补充一下
你可能需要的是一个在线json转struct的工具: https://mholt.github.io/json-to-go/
谢谢大佬,我看网上都是这样的,但以前我c#好像用过一个json库,那个库好像可以直接解析到对应的struct,不用再套一个struct。不知道是怎么实现的。
非常感谢