package main

import (
	"encoding/json"
	"fmt"
	"github.com/iancoleman/orderedmap"
	"github.com/tidwall/gjson"

	//"github.com/tidwall/gjson"
)

func main()  {
	test2();
	return
	jsonStream:= ` 
        {
			"name": {"first": "Tom", "last": "Anderson"},
			"age":37,
			"age1":56.6,
			"age2":"67.3",
			"children": ["Sara","Alex","Jack"],
			"fav.movie": "Deer Hunter",
			"friends": [
				{"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
				{"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
				{"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
			]
		}
    `
	n:=gjson.Get(jsonStream,"abc").Int()
	fmt.Print(n)
	o := orderedmap.New()
	o.UnmarshalJSON([]byte(jsonStream))
	o.Get("children")
	//s:=o.Keys()
	//fmt.Println(s)

	//err := json.Unmarshal([]byte(jsonStream), &o)

	/*json.Unmarshal([]byte(jsonStream),)
	a:=gjson.Parse(jsonStream).Map()*/
	//fmt.Println(a[1].Type)
	//fmt.Print(s)

}

var packConfig string

func test2()  {
	packJson:= ` 
        {
			"编带": {
				"packing": 5,
				"pick_type": 1
			},
			"袋装": {
				"packing": 6,
				"pick_type": 3
			},
			"包": {
				"packing": 6,
				"pick_type": 3
			},
			"管装": {
				"packing": 8,
				"pick_type": 3
			},
			"管": {
				"packing": 8,
				"pick_type": 3
			},
			"盒装": {
				"packing": 7,
				"pick_type": 3
			},
			"盒": {
				"packing": 7,
				"pick_type": 3
			},
			"托盘": {
				"packing": 9,
				"pick_type": 3
			},
			"盘": {
				"packing": 5,
				"pick_type": 1
			},
			"大盘": {
				"packing": 5,
				"pick_type": 1
			}
		}
    `
	o := orderedmap.New()
	err:=o.UnmarshalJSON([]byte(packJson))
	if(err!=nil){
		panic("解析错误")
	}
	//o.Get("dfd")
	s:=gjson.Get(packJson,"abc").String()
	if(s==""){}

}


func PackGet() (*PackData) {
	config:=getConfig()
	s:=gjson.Get(config,"abc").String()
	p:=&PackData{}
	if(s==""){
		return p
	}
	err:=json.Unmarshal([]byte(s),p)
	if(err!=nil){
		panic("mmethod:PackGet"+err.Error())
	}
	return p
}

type PackData struct {
	PacKing int
	PickType int
}

func getConfig()  string{
	if(packConfig!=""){
		return packConfig
	}
	return packConfigs()
}

func packConfigs() string {
	packJson:= ` 
        {
			"编带": {
				"packing": 5,
				"pick_type": 1
			},
			"袋装": {
				"packing": 6,
				"pick_type": 3
			},
			"包": {
				"packing": 6,
				"pick_type": 3
			},
			"管装": {
				"packing": 8,
				"pick_type": 3
			},
			"管": {
				"packing": 8,
				"pick_type": 3
			},
			"盒装": {
				"packing": 7,
				"pick_type": 3
			},
			"盒": {
				"packing": 7,
				"pick_type": 3
			},
			"托盘": {
				"packing": 9,
				"pick_type": 3
			},
			"盘": {
				"packing": 5,
				"pick_type": 1
			},
			"大盘": {
				"packing": 5,
				"pick_type": 1
			}
		}
    `
	return  packJson
}