2014-09-24 70 views

回答

2

不确定JSON在哪里进入。

我猜这就是你追求: http://play.golang.org/p/sEkfcEN2DJ

package main 

import "fmt" 

type Ping struct { 
    Content []aContent 
} 

type aContent struct { 
    Type  string 
    Id   int 
    Created_at int64 
} 

func main() { 

    f := Ping{Content: []aContent{{Type: "Hello", Id: 2}, {Type: "World", Id: 6}}} 

    for i := range f.Content { 
     if f.Content[i].Id > 5 { 
      fmt.Println(f.Content[i]) 
     } 
    } 
} 
+0

感谢。我的不好,我遗漏了JSON位。我更新了Go操场的链接。我的实际代码看起来像这样。我想过滤结果,以便json响应只返回已过滤的结果。 – user3918985 2014-09-24 16:22:43

+1

我已经更新了这个答案:http://play.golang.org/p/j8SK_7NUyY – DanG 2014-09-24 16:41:05

+0

我明白了。我想知道是否有更快,更直接的方式来做到这一点。但是这也起作用。 – user3918985 2014-09-24 16:48:30