Commit 21d37cdf by huangchengyi

1.0

parent cf0e9eb5
Showing with 101 additions and 22 deletions
package model
//联营请求外链后格式化数据
type LyClearData struct {
GoodsID string
GoodsName string
type LyClearGoodsList struct {
GoodsName string `json:"goods_name"`
GoodsNameTemp string `json:"goods_name_temp"`
BrandName string `json:"brand_name"`
Desc string `json:"desc"`
GoodsSn string `json:"goods_sn"`
Docurl string `json:"docurl"`
Url string `json:"url"`
GoodsImg string `json:"goods_img"`
Cat string `json:"cat"`
RestrictionMessage string `json:"RestrictionMessage"`
increment int `json:"increment"`
SinglePrice float64 `json:"single_price"`
Tiered []*TierItem
}
//联营请求外链后格式化数据
type LyClearDataItem struct {
GoodsName string
GoodsNameTemp string
BrandName string
Desc string
GoodsSn string
Docurl string
Url string
GoodsImg string
Cat string
RestrictionMessage string
increment int
SinglePrice float64
PriceTemp []PriceTempItem
}
type PriceTempItem struct {
type TierItem struct {
Purchases int
PriceUs float64
PriceCn float64
PriceAc float64
}
package main
import (
"fmt"
"encoding/json"
)
func main() {
var goodsList []interface{}
var productList map[string]interface{}
var price_temp []interface{}
var tiered []interface{}
m := make(map[string]interface{})
m["goods_names"] = "LM358"
m["stock"] = [...]int64{1,23}
price_temp = append(price_temp,[...]int64{3,5})
m["price_temp"] = price_temp;
s := make(map[string]interface{})
s["purchases"]=1
s["price_us"]=0.66
s["price_us"]=0.67
s["price_cn"]=0.33
tiered = append(tiered,s);
m["tiered"] = tiered;
goodsList = append(goodsList, m)
productList = make(map[string]interface{})
productList["595-LM358BIDR"] = goodsList
productList["595-LM358LVIDDFR"] = goodsList
//map的遍历
for k, v := range productList{
fmt.Println(k,v)
}
jsonStr, err := json.Marshal(productList)
if err!=nil{
return
}
fmt.Printf("%s\n",jsonStr)
}
\ No newline at end of file
package main
import (
"fmt"
"encoding/json"
"search_server/model"
)
func main() {
var LyClearGoodsList model.LyClearGoodsList
LyClearGoodsList.GoodsName = "LM358"
ladderPrice := make([]*model.TierItem, 0)
ladder := model.TierItem{
Purchases: 1,
PriceUs: 0.44,
PriceCn: 1.55,
}
ladderPrice = append(ladderPrice, &ladder)
LyClearGoodsList.Tiered = ladderPrice
var productList map[string]*model.LyClearGoodsList
productList = make(map[string]*model.LyClearGoodsList,0)
productList["595-LM358BIDR"] = &LyClearGoodsList
//map的遍历
for k, v := range productList{
fmt.Println(k,v)
}
jsonStr, err := json.Marshal(productList)
if err!=nil{
return
}
fmt.Printf("%s\n",jsonStr)
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment