我对 Go 很陌生,并且正在使用它进行一些数据操作
我有一个 python 程序,它接受 json 输入,dict of dicts of lists of dicts如下所示:
{
"64": {
"-117": [{
"lat": 64.1121952,
"loc": "Northwest Territories",
"lon": -117.3539847,
"id": "GmtNT",
"name": "Gameti"
}],
"-147": [{
"lat": 64.838,
"loc": "Alaska",
"lon": -147.716,
"id": "FairbanksAK",
"name": "Fairbanks"
},
{
"lat": 64.9,
"loc": "Alaska",
"lon": -147.4,
"id": "IcFgObAK",
"name": "Icefog Observatory"
}]
},
"71": {
"-125": [{
"lat": 71.985123,
"loc": "Northwest Territories",
"lon": -125.2464831,
"id": "SchshrbrNT",
"name": "Sachs Harbour"
}]
}
}
我正在编写一个 Go 脚本来生成这个 json 用于输入。我已经有一个工作脚本可以将数据转换为这种格式:
siteIDMap := make(map[string]map[string]string)
终端中的示例输出:
map[
CydrvrNU: map[loc:Nunavut lat:70.476365 lng:-68.6012651 name:Clyde River]
UkhktkNT: map[loc:Northwest Territories lat:70.7367504 lng:-117.7704441 name:Ulukhaktok]
PrdhByAK: map[loc:Alaska lat:70.254704 lng:-148.3406 name:Prudhoe Bay]
SchshrbrNT: map[loc:Northwest Territories lat:71.985123 lng:-125.2464831 name:Sachs Harbour]
]
但是我在最后一步遇到了麻烦。我已经能够尝试初始化我怀疑是正确的数据类型latLngMap := make(map[string]map[string][]map[string]string),并尝试填充它,但显然不能不初始化每一个 lat/lng 组合!
慕后森
相关分类