go初学爬虫问题,关于切片的用法

s466579141s 2016-10-25 11:56:24

var info map[string]interface{}
var HouseType []map[string]interface{}

var housedetail map[string]interface{}

housedetail["Housetype"] = housetype
housedetail["Housearea"] = housearea
housedetail["HousepriceMax"] = housepriceMax
housedetail["HousepriceMin"] = housepriceMin
housedetail["Housedirection"] = housedirection
housedetail["Housedusage"] = housedusage
housedetail["Housesell"] = housesell
housedetail["Housesdeal"] = housesdeal

HouseType = append(HouseType,housedetail)

info["HouseType"] = HouseType



info是存所有房屋信息的,其中一个数组字段是房型HouseType,里面有很多个map,存了各种房型的信息。
应该就是这一段出了问题跑不了
...全文
1619 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kerr_hg 2016-11-02
  • 打赏
  • 举报
回复
map需要make(或者说new)吧 切片可make 也可以不用make
s466579141s 2016-10-25
  • 打赏
  • 举报
回复
已经解决
package main

import (
	"fmt"
	//"gospider/libs"
)

func main() {

	info := make(map[string]interface{})

	HouseType:= []map[string]interface {}{}

	housedetail := make(map[string]interface{})

	housedetail["Housetype"] = "3房2厅1卫"
	housedetail["Housearea"] = 900

	HouseType = append(HouseType, housedetail)

	info["HouseType"] = HouseType
	info["Price"] = 900
	info["Comp"] = "恒大"

	fmt.Println(info)
}
然而不知道为什么这么写

2,190

社区成员

发帖
与我相关
我的任务
社区描述
go语言学习与交流版
社区管理员
  • go语言社区
  • Freeman Z
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧