1 回答
TA贡献1852条经验 获得超7个赞
migrations, migrations1 := make(map[string]interface{}), make(map[string]interface{})
data := `{ "name":"Kate", "date":"2012-04-23T18:24:59.511Z", "data":"is nice" }`
data1 := `{ "name":"Gleison", "date":"2012-04-23T18:25:00.511Z", "data":"is a good person" }`
err := json.Unmarshal([]byte(data), &migrations)
if err != nil {
panic(err)
}
err = json.Unmarshal([]byte(data1), &migrations1)
if err != nil {
panic(err)
}
layout := "2006-01-02T15:04:05.000Z"
t, err := time.Parse(layout, fmt.Sprint(migrations["date"]))
t1, err := time.Parse(layout, fmt.Sprint(migrations1["date"]))
if err != nil {
fmt.Println(err)
}
firsthour := t.Hour()
secondhour := t1.Hour()
if firsthour == secondhour {
result := make(map[string][]interface{})
for k, v := range migrations {
result[k] = append(result[k], v)
}
for k, v := range migrations1 {
result[k] = append(result[k], v)
}
fmt.Println(result)
b, err := json.Marshal(result)
if err != nil {
fmt.Println(err)
}
os.Stdout.Write(b)
} else {
err = json.Unmarshal([]byte(data), &migrations)
if err != nil {
panic(err)
}
err = json.Unmarshal([]byte(data1), &migrations1)
if err != nil {
panic(err)
}
fmt.Println(migrations, migrations)
}
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报