为了账号安全,请及时绑定邮箱和手机立即绑定

GoLang 中的 Marshall 和 UnMarshall JSON 内容

GoLang 中的 Marshall 和 UnMarshall JSON 内容

Go
梵蒂冈之花 2021-07-08 21:18:23
我有一个示例 json 文件,其结构如下{  "method":"brute_force",  "bc":"select * from blah;",  "gc":[    "select sum(year) from blah;",    "select count(*) from table;"      ]}我正在尝试编写一个可以读取此文件并操作 json 内容的 go 程序。package main import (    "fmt"    "encoding/json"    "io/ioutil"    )type Response2 struct {    method string    bc string    gc []string}func main() {    file,_ := ioutil.ReadFile("config.json")    fmt.Printf("%s",string(file))        res := &Response2{}        json.Unmarshal([]byte(string(file)), &res)        fmt.Println(res)        fmt.Println(res.method)        fmt.Println(res.gc)}res.method 和 res.gc 不打印任何东西。我不知道出了什么问题。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 294 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信