Quantcast
Channel: Cannot convert string map to json - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Cerise Limón for Cannot convert string map to json

$
0
0

The variable jmap is type []byte. The call to JSON encoder in c.JSON() marshals []byte as a base64 encoded string as you see in the output.

To fix the problem, use one level of JSON encoding by passing the map directly to c.JSON:

hashMap, err := redis.StringMap(conn.Do("HGETALL", MyDict))
if err != nil {
    // handle error
}    
m := make(map[string]string)
for k, v := range hashMap {
    m[k] = v
}

c.JSON(200, m)

Because hashMap is a map[string]string, you can use it directly:

hashMap, err := redis.StringMap(conn.Do("HGETALL", MyDict))
if err != nil {
    // handle error
}    
c.JSON(200, hashMap)

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>