2015-07-23 20:34


  • json

I have the following in my json array (conf.json file).

  "Repos": [

I am attempting to read this json and then iterate over it but get stuck. I am very new to go (and to programming) so I am having a hard time understanding what is happening here.

import (

type Configuration struct {
    Repos []string

func read_config() {
    file, _ := os.Open("conf.json")
    decoder := json.NewDecoder(file)
    configuration := Configuration{}
    err := decoder.Decode(&configuration)
    if err != nil {
        fmt.Println("error:", err)


So far this is as far as I have been able to get. This will print out the values okay, [a, b, c].

What I would like to do is be able to iterate over the array and split out each value individually but have not had any luck at doing this. Am I taking the wrong approach to this? Is there a better way to do this?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享