[英]Go: Filter JSON response
I'm trying to return a json response that is filtered by only taking the struct values if the id is > 5. 我试图返回一个json响应,如果id> 5,则仅通过采用struct值进行过滤。
A sample base code can be found here: http://play.golang.org/p/4ORba3y7F7 可在此处找到示例基本代码: http : //play.golang.org/p/4ORba3y7F7
How do I filter the json results? 如何过滤json结果?
Not sure where JSON comes into it. 不知道JSON进入哪里。
I'm guessing this is what you're after: http://play.golang.org/p/sEkfcEN2DJ 我猜这就是您的追求: 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])
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.