当前位置:网站首页>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:
边栏推荐
猜你喜欢

window远程桌面连接互传文件加速小技巧

Detailed explanation of MQ message oriented middleware theory

Sleuth + Zipkin

js 递归json树 根据 子id 查 父id

SaaS cloud tool, a sharp tool for change under the industrial Internet

Interpreting the 2022 agile coaching industry status report

Block, non block, multiplexing, synchronous, asynchronous, bio, NiO, AIO

【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
![Generating binary search balanced tree [using tree recursion]](/img/b3/f8edf45bdfdced7c3698088dbf7d84.png)
Generating binary search balanced tree [using tree recursion]

Tips for accelerating file transfer between windows remote desktop connections
随机推荐
将vscode打造无敌的IDE(14) tasks.json和launch.json配置详解,随心所欲添加自动化任务
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
Image saving: torchvision utils. save_ image(img, imgPath)
六石编程学:运用之妙,存乎一心
Tips for using JS objects
Object
golang goroutine、channel、time代码示例
Object
HBuilderX-Light 主题能不能加个批注功能?
Web articles_ 01 understanding web development
【TcaplusDB知识库】Tmonitor单机安装指引介绍(二)
融云:让银行轻松上“云”
创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
stylegan2:analyzing and improving the image quality of stylegan
How NPM contracts and deletes packages
Example of if directly judging data type in JS
【TcaplusDB知识库】TcaplusDB新增机型介绍
Use of iscellstr function in MATLAB
Advanced development - generic entry basic class test
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)