当前位置:网站首页>Golang writes to JSON files
Golang writes to JSON files
2022-06-23 16:23:00 【Learn programming notes】
Go Language JSON Read and write operation of the file
package main
import (
"encoding/json"
"fmt"
"os"
)
type Website struct {
Name string `xml:"name,attr"`
Url string
Course []string
}
func main() {
info := []Website{
{
"Golang", "http://c.biancheng.net/golang/", []string{
"http://c.biancheng.net/cplus/", "http://c.biancheng.net/linux_tutorial/"}}, {
"Java", "http://c.biancheng.net/java/", []string{
"http://c.biancheng.net/socket/", "http://c.biancheng.net/python/"}}}
// create a file
filePtr, err := os.Create("info.json")
if err != nil {
fmt.Println(" File creation failed ", err.Error())
return
}
defer filePtr.Close()
// establish json Encoder
encoder := json.NewEncoder(filePtr)
err = encoder.Encode(info)
if err != nil {
fmt.Println(" Coding errors ", err.Error())
} else {
fmt.Println(" Coding succeeded ")
}
}
info.json:
边栏推荐
- 总结一下购买阿里云服务器的经验
- How does the web container initialize third-party plug-ins
- How to quickly respond to changing production management needs?
- 《ThreadLocal》
- Readimg: read picture to variable variable variable
- Sleuth + Zipkin
- Pytorch: saving and exporting models
- 提高效率 Or 增加成本,开发人员应如何理解结对编程?
- 【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)
- js 递归json树 根据 子id 查 父id
猜你喜欢

Summarize the experience of purchasing Alibaba cloud servers

leetcode:30. 串联所有单词的子串【Counter匹配 + 剪枝】

机器人方向与高考选专业的一些误区

stylegan1: a style-based henerator architecture for gemerative adversarial networks

XML

How did Tencent's technology bulls complete the overall cloud launch?

《Apache Commons 工具类》

多年亿级流量下的高并发经验总结,都毫无保留地写在了这本书中
![[tcapulusdb knowledge base] Introduction to new models of tcapulusdb](/img/2a/1d7f12c99b92d143e142ade8bc90f9.png)
[tcapulusdb knowledge base] Introduction to new models of tcapulusdb
![[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)](/img/6d/8b1ac734cd95fb29e576aa3eee1b33.png)
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)
随机推荐
【TcaplusDB知识库】TcaplusDB新增机型介绍
Interpreting the 2022 agile coaching industry status report
批量注册组件
【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)
创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
Readimg: read picture to variable variable variable
解读2022年度敏捷教练行业现状报告
Generating binary search balanced tree [using tree recursion]
Apache commons tool class
Amadis发布OLA支付处理标准
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (II)
Tips for using JS objects
SSRS页面配置Postgresql data source的方法
Web篇_01 了解web開發
泰山OFFICE技术讲座:使用字体斜体的四种情形
【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)
XML
How to configure PostgreSQL data source on SSRs page
如何让销售管理更高效?
513. Find Bottom Left Tree Value