当前位置:网站首页>Golang对JSON文件的写操作
Golang对JSON文件的写操作
2022-06-23 15:38:00 【学亮编程手记】
Go语言JSON文件的读写操作
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/"}}}
// 创建文件
filePtr, err := os.Create("info.json")
if err != nil {
fmt.Println("文件创建失败", err.Error())
return
}
defer filePtr.Close()
// 创建 json 编码器
encoder := json.NewEncoder(filePtr)
err = encoder.Encode(info)
if err != nil {
fmt.Println("编码错误", err.Error())
} else {
fmt.Println("编码成功")
}
}
info.json:
边栏推荐
- 六石编程学:运用之妙,存乎一心
- Advanced development - generic entry basic class test
- 为什么高通滤波器也能变成微分器?
- R语言使用tidyquant包的tq_transmute函数计算持有某只股票的天、月、周收益率、ggplot2使用条形图(bar plot)可视化股票月收益率数据、使用百分比显示Y轴坐标数据
- pytorch:模型的保存与导出
- matlab: 如何从一些数据里知道是由哪些数据相加得出一个已知数
- VGG下载(.net文件和imagenet-vgg-verydeep-19)
- How is it cheaper to open a stock account? Is it safe to open an account online now?
- stylegan3:alias-free generative adversarial networks
- Web篇_01 了解web開發
猜你喜欢

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

《ThreadLocal》

融云:让银行轻松上“云”

SaaS cloud tool, a sharp tool for change under the industrial Internet
Drag the child file to the upper level
![[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)](/img/d7/3a514fb75b3df487914a8db245ab89.png)
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)

Ten thousand words introduction, detailed explanation of the core technical points of Tencent interview (t1-t9), and arrangement of interview questions
![[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (I)](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (I)
![[tcapulusdb knowledge base] Introduction to new models of tcapulusdb](/img/2a/1d7f12c99b92d143e142ade8bc90f9.png)
[tcapulusdb knowledge base] Introduction to new models of tcapulusdb

SaaS 云工具,产业互联网下的变革利器
随机推荐
js中 if 直接判断 数据类型 结果举例
Improving efficiency or increasing costs, how should developers understand pair programming?
腾讯的技术牛人们,是如何完成全面上云这件事儿的?
mysql事务与锁
港股多支个股表现活跃,引发投资者对港股市场回暖猜想与关注
PageHelper在面对复杂service数据处理下的分页问题
企业想上MES系统?还得满足这些条件
How to open a stock account? Is online account opening safe?
生成二叉搜索平衡树[利用树递归特性]
MES在流程和离散制造企业的15个差别(上)
Advanced development stage - the thickening of potential suspension wire begins A small step now, a big step next year
ADB key name, key code number and key description comparison table
freemark 使用ftl文件 生成word
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(上)
R语言使用tidyquant包的tq_transmute函数计算持有某只股票的天、月、周收益率、ggplot2使用条形图(bar plot)可视化股票月收益率数据、使用百分比显示Y轴坐标数据
《ThreadLocal》
Chapitre Web 01 comprendre le développement web
matlab: 如何从一些数据里知道是由哪些数据相加得出一个已知数
怎样快速的应对变动的生产管理需求?
进阶开发阶段-势若悬丝的加粗开始. 现在的一小步,明年的一大步