1. 首页
  2. 主题
  3. Go问与答

新人求问json转struct

zucifer · · 1369 次点击
我有一串json[{"id":1},{"id":2}....] 试图定义为struct ```go type A struct { Nodes []Node `json:"node"` } type Node struct { Id string `json:"id"` } ``` 可是无法转化 请问 这struct应该如何定义
直接使用 []Node 接收。 你定义一个 A,tag 有 node,但你的 json 并没有 node 啊
#1
更多评论
Id string 应该是id int json也是有类型的 然后,你json里没有node 。 按你的范例,应该是 type A []Node
#2
理解了 感谢大家 我这里直接定义了一个NODE 就能把数组插入了 type Node struct { Id int } 然后直接解析了
#3

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中