1 回答
TA贡献1779条经验 获得超6个赞
Result.Array()Result将当前结果转换为( )的切片[]Result。因此,您可以只为您想要的范围取一片。例如resultPriod.Array()[0:12]获取前 12 个元素。
以此简化版为例:
func main() {
jsonString := `
{
"PaymentCalendarList": {
"PaymentCalendar": [
{"ContractSubmitted": 10,
"Date": "2018-01-01T01:01:01"},
{"ContractSubmitted": 20,
"Date": "2018-01-01T02:02:02"},
{"ContractSubmitted": 30,
"Date": "2018-01-01T03:03:03"}
{"ContractSubmitted": 40,
"Date": "2018-01-01T04:04:04"}
{"ContractSubmitted": 50,
"Date": "2018-01-01T05:05:05"}
]
}
}`
tempPayments := "PaymentCalendarList.PaymentCalendar."
resultPeriod := gjson.Get(jsonString, tempPayments+"#.Date")
# Take the first 3 results
for _, datePeriod := range resultPeriod.Array()[0:3] {
fmt.Println(datePeriod)
}
}
- 1 回答
- 0 关注
- 91 浏览
添加回答
举报