从字符串中删除反斜杠

I want to send the string to the server.My string is like as below,

  str := "[{\"name\":\"cpu\",\"status\":\"%d\"}, {\"name\":\"LTE\",\"status\":\"%d\"}, {\"name\":\"Network\",\"status\":\"%d\"}, {\"name\":\"Memory\",\"status\":\"%d\"}]"

When I print it using "fmt.Println(str)",it gives desired output as below,

[{"name":"cpu","status":"%d"}, {"name":"LTE","status":"%d"}, {"name":"Network","status":"%d"}, {"name":"Memory","status":"%d"}]

But when I am sending same string to server,server receives string as below,

"[{\"name\":\"cpu\",\"status\":\"%d\"}, {\"name\":\"LTE\",\"status\":\"%d\"}, {\"name\":\"Network\",\"status\":\"%d\"}, {\"name\":\"Memory\",\"status\":\"%d\"}]"

Please find my code snippet as below:

func (m *MetricSet) Fetch() (common.MapStr, error) {
        var x string
        x =fmt.Sprintf("[{\"name\":\"cpu\",\"status\":\"%d\"}, {\"name\":\"LTE\",\"status\":\"%d\"}, {\"name\":\"Network\",\"status\":\"%d\"}, {\"name\":\"Memory\",\"status\":\"%d\"}]", 17,26,34,33)
        fmt.Println(x)
        event := common.MapStr{
                "cpu_status": (m.cpu_status%4),
                "memory_status" : (m.memory_status%4),
                "lte_status" : (m.lte_status%4),
                "network_status" : (m.network_status%4),
                "summary": x,
        }

        m.cpu_status++
        m.memory_status = m.memory_status + 2
        m.lte_status = m.lte_status + 7
        m.network_status = m.network_status + 13

        return event, nil
}

How to solve it?Please help me.

You are sending the content of summary as a string so, instead you need to send it as a slice of maps

k := [...]common.MapStr{
    {"name": "cpu", "status": m.cpu_status},
    {"name": "LTE", "status": m.lte_status},
    {"name": "Network", "status": m.network_status},
    {"name": "Memory", "status": m.memory_status},
}
event := common.MapStr{
    "cpu_status":     (m.cpu_status % 4),
    "memory_status":  (m.memory_status % 4),
    "lte_status":     (m.lte_status % 4),
    "network_status": (m.network_status % 4),
    "summary":        k,
}

See https://play.golang.org/p/yTSXnNKclG

When event is marshalled into JSON, the value of summary will be escaped if it contains a double quote. The quick and dirty solution will be defined the event as map[string]interface{} to be able to store arbitrary type as map value, and store the summary value as json.RawMessage e.g.

event := map[string]interface{}{
    "cpu_status": (m.cpu_status%4),
    "memory_status" : (m.memory_status%4),
    "lte_status" : (m.lte_status%4),
    "network_status" : (m.network_status%4),
    "summary": json.RawMessage(x),
}

However, you need to make sure that the value of x is a valid JSON object (which is error prone). More robust solution is by defining the items in summary as a struct type, e.g.

type Status struct {
    Name string `json:"name"`
    Status string `json:"status"`
}
summary := []*Status{
    &Status{"cpu", "17"},
    &Status{"LTE", "26"},
    &Status{"Network", "34"},
    &Status{"Memory", "33"},
}

event := map[string]interface{}{
    "cpu_status": (m.cpu_status%4),
    "memory_status" : (m.memory_status%4),
    "lte_status" : (m.lte_status%4),
    "network_status" : (m.network_status%4),
    "summary": summary,
}