json.Unmarshal不返回解码数据

json.Unmarshal不返回解码数据,json,go,Json,Go,我在解压从.json文件读取的json数据时遇到问题 type redisConfig struct { host string password string } func loadRedisConfig() (redisConfig, error){ b, _ := ioutil.ReadFile("config.json") var config redisConfig fmt.Println(b) fmt.Println(string(b

我在解压从
.json
文件读取的json数据时遇到问题

type redisConfig struct {
    host string
    password string
}

func loadRedisConfig() (redisConfig, error){
    b, _ := ioutil.ReadFile("config.json")
    var config redisConfig
    fmt.Println(b)
    fmt.Println(string(b))


    e := json.Unmarshal(b, &config)

    fmt.Println(e)

    fmt.Println(config)
    return config, nil;
}
文件
config.json
包含以下内容:

{
  "host": "example.com",
  "password": "password"
}
我已经用JSON验证了它是有效的。阅读这里的其他类似问题,我发现问题是无效的json,我认为这里不是这样

以下是运行代码段的输出:

[123 13 10 32 32 34 104 111 115 116 34 58 32 34 101 120 97 109 112 108 101 46 99 111 109 34 44 13 10 32 32 34 112 97 115 115 119 111 114 100 34 58 32 34 112 97 115 115 119 111 114 100 34 13 10 125]
{
  "host": "example.com",
  "password": "password"
}
<nil>
{ }
[123 13 10 32 34 104 111 116 34 58 32 34 101 120 97 109 112 108 101 46 99 111 109 34 44 10 32 32 34 112 97 115 119 111 100 34 58 32 34 112 97 115 115 115 119 111 114 100 34 13 10 125]
{
“主机”:“example.com”,
“密码”:“密码”
}
{ }
config
变量包含一个空结构,应使用文件提供的封送json填充该结构,解码器将仅设置结构的导出字段。
只需将字段公开(导出):


使用
ioutil.ReadFile(“config.json”)

输出:

{example.com password123}
{example.com password123}

尝试:

输出:

{example.com password123}
{example.com password123}

我曾经尝试过从代码中的硬编码字符串中解组。没问题,它工作得很好。不知何故,它从磁盘中提取的数据肯定已损坏。这就是为什么我要打印从磁盘读取的字符串和字节数组,但它们看起来都很好。我在windows上,所以我的操作系统可能会有一些恶作剧?哦,好吧,把结构变量改成大写就行了,它们需要公开。啊!非常感谢!
{example.com password123}