dousonghs58612
dousonghs58612
2016-07-30 10:04

使用包含下划线的字段名称解析JSON

已采纳

So I have JSON like this

{"Name":"Jame","Age":6,"Original_Name":"Jameson"}

In order to get "Name" and "Age" in Go, I just need to use a corresponding struct

type Result struct {
  Name string
  Age int
}

But how do I get the field "Original_Name" since I cannot use underscore in go?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanbimo7212 duanbimo7212 5年前

    Does this work:

    type Result struct {
      Name string
      Age int
      Originalname string `json:"Original_Name"`
    }
    
    点赞 评论 复制链接分享