go语言中数据转换

wendo · · 1480 次点击
1 for k, v := range hits["highlight"].(map[string]interface{}) {} 2 j, _ :=json.Marshal(hits["highlight"].(map[string]interface{})) json :=string(j)
#1
更多评论
```go {"name":["\u003cfont color ='red'\u003eNew\u003c/font\u003e \u003cfont color 'red'\u003eYork\u003c/font\u003e "]} ``` 谢谢,HTML被转义了
#2
```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