douxiong2738
2018-11-29 11:34
浏览 73
已采纳

如何在golang中解析json数组结构

im using the following code without success to parse json value but its inside array []

https://play.golang.org/p/5HdWeyEtvie

package main

import (
    "encoding/json"
    "fmt"
)


var input = `
[
{
    "created_at": "Thu May 31 00:00:01 +0000 2012"
},
{
    "created_at": "Thu May 31 00:00:01 +0000 2012"
}
]
`

func main() {
    var val map[string]interface{}
    if err := json.Unmarshal([]byte(input), &val); err != nil {
        panic(err)
    }
    fmt.Println(val)
}

The idea is to get the value as key and print it , like a function that get string parameter="created_at" and prints it.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题