3

golang json save 保存

 3 years ago
source link: https://studygolang.com/articles/803?fr=sidebar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

golang json save 保存

koalaone · 2014-10-04 19:27:29 · 5165 次点击 · 预计阅读时间不到 1 分钟 · 大约8小时之前 开始浏览    
这是一个创建于 2014-10-04 19:27:29 的文章,其中的信息可能已经有所发展或是发生改变。

go-simplejson和beego中的config,json都没有保存json内容

以go-simplejson为列,在文件中增加如下就行:

func SaveFile(filename string, json *Json) (bool, error) {
    saveData, _ := json.MarshalJSON()
    err := ioutil.WriteFile(filename, saveData, os.ModeAppend)
    if err != nil {
        return false, err
    }
    return true, nil
}

beego中的json,类推增加


有疑问加站长微信联系(非本文作者)

280

本文来自:开源中国博客

感谢作者:koalaone

查看原文:golang json save 保存

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:701969077


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK