Answer the question
In order to leave comments, you need to log in
How to parse json file in Go?
I have a json file
[{"server":"28773abe-e620-4d36-9512-c6f4b128f0ad"},{"server":"11c044ac-00eb-4fc6-9c30-fccab0ba8cda"}...]
type Servers struct {
Server string `json:"server"`
}
const slist = "global_servers.json"
func Firstfunc() {
f, err := os.Open(slist)
if nil != err {
log.Fatalln(err)
}
defer f.Close()
dec := json.NewDecoder(f)
db := []Servers{}
dec.Decode(&db)
fmt.Println(db)
for field, value := range db {
fmt.Print(field, "\n")
fmt.Print(value, "\n")
// в value получаю {28773abe-e620-4d36-9512-c6f4b128f0ad}
// нужна строка 28773abe-e620-4d36-9512-c6f4b128f0ad
// и вот здесь хотелось бы Secondfunc(value), но ошибка
}
}
func Secondfunc(srt string) {
fmt.Println(srt)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question