Skip to content

Instantly share code, notes, and snippets.

@tenntenn
Created February 2, 2014 15:46
Show Gist options
  • Save tenntenn/8770296 to your computer and use it in GitHub Desktop.
Save tenntenn/8770296 to your computer and use it in GitHub Desktop.
[Go言語] JSONを解析するのに、型作るのはめんどい ref: http://qiita.com/tenntenn/items/1c0d6b0523992f38bfd0
package main
import (
"github.com/tenntenn/gj"
"fmt"
"io/ioutil"
"os"
)
func main() {
jsonStr, _ := ioutil.ReadAll(os.Stdin)
v, _ := gj.New(jsonStr)
traversal(v.Slice(1, v.Len()))
}
func traversal(v *gj.Value) {
if v.IsArray() {
v.EachIndex(func(i int, v *gj.Value) {
traversal(v)
})
return
}
if v.IsObject() {
if v.Has("type") && v.Get("type").String() == "ResourceSendRequest" {
fmt.Println(v.Get("data").Get("url").String())
}
if v.Has("children") {
traversal(v.Get("children"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment