Всем привет.
Есть data.json:
[
{
"database": {
"id": "1",
"access_token": "mxtM7SPJuTPDvy0",
"chanel_id": "-106",
"timezone": "3",
"time": "12452345"
},
"text": "Hello my chanel.",
"photo_link": false,
"audio_link": false,
"mov_link": false,
"markdown": true,
},
{
"database": {
"id": "1",
"access_token": "mxtM7SPJuTPDvy0",
"chanel_id": "-10011",
"timezone": "3",
"time": "12452345"
},
"text": "Hello my chanel.",
"photo_link": false,
"audio_link": false,
"mov_link": false,
"markdown": true
},
{
"database": {
"id": "1",
"access_token": "mxtM7SPJuTPDvy0",
"chanel_id": "-10011",
"timezone": "3",
"time": "12452345"
},
"text": "Hello my chanel.",
"photo_link": false,
"audio_link": false,
"mov_link": false,
"markdown": true
},
{
"database": {
"id": "1",
"access_token": "mxtM7SPJuTPDvy0",
"chanel_id": "-100",
"timezone": "3",
"time": "12452345"
},
"text": "Hello my chanel.",
"photo_link": false,
"audio_link": false,
"mov_link": false,
"markdown": true
}
]
есть go код :
package main
import (
"fmt"
"os"
"encoding/json"
)
type Config struct {
Database struct {
Id int `json:"id"`
Access_token string `json:"access_token"`
Chanel_id int64 `json:"chanel_id"`
Timezone string `json:"timezone"`
Time int `json:"time"`
} `json:"database"`
Text string `json:"text"`
Photo_link string `json:"photo_link"`
Audio_link string `json:"audio_link"`
Mov_link string `json:"mov_link"`
Markdown string`json:"markdown"`
}
func LoadConfiguration(file string)(Config, error) {
var config Config
configFile, err := os.Open(file)
defer configFile.Close()
if err != nil {
return config, err
}
jsonParser := json.NewDecoder(configFile)
err = jsonParser.Decode(&config)
return config, err
}
func main() {
config, _ := LoadConfiguration(`data.json`)
fmt.Println(config.Database.Id)
}
Все время выдает пустую строку.