I'm trying to parse a json object, get a specific field session_id
as []byte
.
func login() {
var jsonObj map[string]interface{}
json.Unmarshal(body, &jsonObj)
content := jsonObj["content"].(map[string]interface{})
sid := content["session_id"].([]byte)
}
Where, body
is the json object from the HTTP response. It looks like this:
{
"seq": 0,
"status": 0,
"content": {
"session_id": "abcd1234efgh5678",
"config": {
"icons_dir": "feed-icons",
"icons_url": "feed-icons",
"daemon_is_running": true,
"custom_sort_types": [],
"num_feeds": 2
},
"api_level": 18
}
}
My code panics on the last line, saying: panic: interface conversion: interface {} is string, not []uint8
If I change the last line to below then it works:
sid := content["session_id"].(string)
sidbytes := []byte(sid)
I'm assuming in the error message "interface {} is string" refers to "abcd1234efgh5678" being a string, and uint8 is byte (which makes sense but)? What am I misunderstanding here?