Hey. I had this problem. There is a string-json, which is converted to a map. Inside this line is an array. The problem is as follows. The Unmarshall function converts the string to json, after which I try to get the above array, but I get the error:
panic: interface conversion: interface {} is []interface {}, not map[int]int I give an example of json ʻa:
map[lon:52.328066 fias_id:89bc3c83-6060-4737-a497-0d4e64cdff16 polygon_osm_id:0 path:Россия, Кировская область, Верхнекамский район, Пещера, Нижняя улица place_type: is_capital:0 official_status_ru: alt_names:[] info:{} id:376672 msg: type:street lat:59.192944 name:Нижняя улица parent_id:376618 parent_ids:[0 1 72 371251 376618]] I want to get parent_ids . I do it like this:
parent := dataJson["parent_ids"].(map[int]int) // Здесь падает программа A piece of code that performs the conversion:
json.Unmarshal(bytes, &dataJson) fmt.Println(dataJson) parent := dataJson["parent_ids"].(map[int]int) How to solve this problem?
parent_idsis a slice, not a map. And by the way, your data normally falls on the structure, so why are you doing through themap? - Ainar-G