1
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package tiktok_api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
freightTemplate_create_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/freightTemplate_create/request"
|
||||
freightTemplate_update_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/freightTemplate_update/request"
|
||||
@@ -446,20 +448,29 @@ func TestPrint(t *testing.T) {
|
||||
globals.SugarLogger.Debugf("%d", []int{1, 2, 3, 46, 65})
|
||||
}
|
||||
|
||||
//func TestToMap(t *testing.T) {
|
||||
// data:=" "57939570":[{"123":"987"},{"124":"988"},{"125":"989"},{"126":"990"},{"127":"991"}] "
|
||||
// result, err := utils.Unmarshal2Map([]byte(data), &payload)
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func toMap(actual interface{}) ([]string, error) {
|
||||
// var res []string
|
||||
// value := reflect.ValueOf(actual)
|
||||
// if value.Kind() != reflect.Slice && value.Kind() != reflect.Array {
|
||||
// return nil, errors.New("parse error")
|
||||
// }
|
||||
// for i := 0; i < value.Len(); i++ {
|
||||
// res = append(res, value.Index(i).Interface().(string))
|
||||
// }
|
||||
// return res, nil
|
||||
//}
|
||||
type RelInfo struct {
|
||||
StoreID string `json:"storeID"`
|
||||
VendorStoreID string `json:"vendorStoreID"`
|
||||
}
|
||||
|
||||
func TestToMap(t *testing.T) {
|
||||
data := `{"57939570":[{"100329":"63517290"},{"102039":"63517652"}]}`
|
||||
payload := make(map[string][]RelInfo)
|
||||
err := UnmarshalUseNumber([]byte(data), &payload)
|
||||
fmt.Println(payload)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
func UnmarshalUseNumber(data []byte, result interface{}) error {
|
||||
err := TryUnmarshalUseNumber(data, result)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Infof("decode data:%v, error:%v", string(data), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func TryUnmarshalUseNumber(data []byte, result interface{}) error {
|
||||
d := json.NewDecoder(bytes.NewReader(data))
|
||||
d.UseNumber()
|
||||
return d.Decode(result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user