```go
map[
hits:[
map[
_id:OQpf7HYBhW0_ej1URQbB
_index:student
_score:0.5753642
_source:map[name:New York]
_type:_doc
highlight:map[name:[<font color ='red'>New</font> <font color ='red'>York</font>]]
]
]
max_score:0.5753642
total:map[relation:eq value:1]
]
```
新人请教问题:
**1、怎么遍历取出highlight中的值?**
**2、数据怎么转成json格式?**
```go
{"name":["\u003cfont color ='red'\u003eNew\u003c/font\u003e \u003cfont color 'red'\u003eYork\u003c/font\u003e "]}
```
谢谢,HTML被转义了
#2
更多评论
1
for k, v := range hits["highlight"].(map[string]interface{}) {}
2
j, _ :=json.Marshal(hits["highlight"].(map[string]interface{}))
json :=string(j)
#1
```go
total := make(map[string]interface{})
total["relation"] = "eq"
total["value"] = 1
highlight := make(map[string][]interface{})
highlight["name"] = []interface{}{`<font color ='red'>New</font> <font color ='red'>York</font>`}
hits := make([]map[string]interface{},0)
hitmp := make(map[string]interface{})
hitmp["_id"] = "OQpf7HYBhW0_ej1URQbB"
hitmp["_index"] = "student"
hitmp["_score"] = 0.5753642
hitmp["type"] = "doc"
hitmp["highlight"] = highlight
hits = append(hits,hitmp)
tmp := make(map[string]interface{})
tmp["max_score"] = 0.5753642
tmp["total"] = total
tmp["hits"] = hits
//fmt.Println(tmp)
//sm,_ := json.Marshal(tmp)
buf := bytes.NewBuffer([]byte{})
jsencode := json.NewEncoder(buf)
jsencode.SetEscapeHTML(false)
jsencode.Encode(tmp)
fmt.Println(buf.String())
```
不知道这个是不是你想要的结果
#3