人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。

 

package main
import (
    "encoding/json"
    "io/ioutil"
    "time"
    "strconv"
    "fmt"
)

//要先定义json格式的结构体
type publishJson struct {
    BgId             string  `json:"bgId"`
    CandBgColor      string  `json:"candBgColor"`
    CurKbType        int     `json:"curKbType"`
    EffectId         string  `json:"effectId"`
    FontColor        string  `json:"fontColor"`
    FontColorChanged bool    `json:"fontColorChanged"`
    FontId           string  `json:"fontId"`
    KeyId            string  `json:"keyId"`
    KeyTransparent   float64 `json:"keyTransparent"`
    KeyboardBgName   string  `json:"keyboardBgName"`
    LocalSkinId      string  `json:"localSkinId"`
    Platform         int     `json:"platform"`
    PreviewName26    string  `json:"previewName26"`
    PreviewName9     string  `json:"previewName9"`
    SkinName         string  `json:"skinName"`
    SoundId          string  `json:"soundId"`
    UgcSkinVersion   int     `json:"ugcSkinVersion"`
    UseCustomBg      bool    `json:"useCustomBg"`
}


func main() {
    updateFile := "theme_publish.json"
    now := strconv.FormatInt(time.Now().UnixNano(), 10)
    write(now, updateFile)
}
func write(now string, path string) error{
    var loacl string = now
    //初始化结构体内的json字段内容
    theme_publish1 := publishJson{
        BgId:             "351",
        CandBgColor:      "0xdffffcfc",
        CurKbType:        2,
        EffectId:         "-1",
        FontColor:        "0xff000000",
        FontColorChanged: false,
        FontId:           "-1",
        KeyId:            "10",
        KeyTransparent:   59.025097,
        KeyboardBgName:   "keyboard_bg.png",
        LocalSkinId:      "loacl",
        Platform:         1,
        PreviewName26:    "",
        PreviewName9:     "square_preview.png",
        SkinName:         "bbb",
        SoundId:          "-1",
        UgcSkinVersion:   1,
        UseCustomBg:      false,
    }

    theme_publish1.LocalSkinId = loacl
    //将结构体转为json格式
    data, err := json.Marshal(theme_publish1)
    checkError(err)
    //将json格式的数据写入文件
    err = ioutil.WriteFile(path, data, 0777)
    checkError(err)
    return nil
}

func checkError(err error) {
    if err != nil {
        fmt.Println(err)
        panic(err)
    }
}

 

posted on 2021-10-08 15:46  测试开发喵  阅读(708)  评论(0编辑  收藏  举报