-3

我正在尝试使用 GoLang 解析 json 文件,但它似乎不起作用。我做得对吗?

这是我的 Go 代码:

package main

import (
    "encoding/json"
    "fmt"
    "io/ioutil"
)

type info struct {
    username   string   `json:"username"`
    password   string   `json:"password"`
    timedelay  int      `json:"timedelay"`
    courselist []string `json:"courselist"`
}

func main() {
    var jsonParse info
    file, err := ioutil.ReadFile("info.json")
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println("My file content is:\n", string(file))
    fmt.Println("---------------Parsing Json File----------------")

    json.Unmarshal(file, &jsonParse)
    fmt.Println("My Json Parse is:\n", jsonParse)

}

这是我的 json 文件

{
    "username" : "17020726",
    "password": "Blueflower",
    "timedelay": 200,
    "courselist": ["54"]
}

这是我的代码的结果

My file content is:
 {
    "username" : "17020726",
    "password": "Blueflower",
    "timedelay": 200,
    "courselist": ["54"]
}
---------------Parsing Json File----------------
My Json Parse is:
 {  0 []}
4

1 回答 1

3

信息结构字段是私有的。首字母大写。

于 2019-08-18T03:43:48.363 回答