var rbody []map[string]interface{}
t :=make(map[string]interface{})
t["currenttime"] ="dddddd"
t["starttime"] ="ddddddd"
rbody =append(rbody,t)
cnnJson :=make(map[string]interface{})
cnnJson["code"] =0
cnnJson["msg"] ="ok ar you ok"
cnnJson["rbody"] =rbody
b,json_err :=json.Marshal(cnnJson)//json化结果集
if json_err !=nil {
fmt.Println("encoding faild")
}else {
fmt.Println(string(b))
}
最后生成的格式
{
"code": 0,
"msg": "ok ar you ok",
"rbody": [
{
"currenttime": "dddddd",
"starttime": "ddddddd"
}
]
}