当前位置:网站首页>How to use unmarshaljson
How to use unmarshaljson
2022-06-30 06:02:00 【Flower master】
Writing go In the process of , Upstream is always free to transfer any type of data . This will lead to our small go This clean language reports errors when parsing parameters because the data type is wrong . therefore UnmarshalJSON The application of
Specific use :
package main
import (
"encoding/json"
"fmt"
)
type App struct {
Boottime String `json:"boottime"` // Here is the user-defined parameter type when receiving String
}
type String string
func main() {
app := &App{}
a := `{"boottime":1732323232}`
err := json.Unmarshal([]byte(a),&app)
if err != nil {
fmt.Println(err)
}
fmt.Println(app)
}
// Type conversion is done here
func (s *String) UnmarshalJSON(data []byte) error{
*s = String(data)
return nil
}
It's easy to implement . In fact, it is resolved to boottime Through unmarshalJson Convert types . Very good and practical
边栏推荐
- 880. 索引处的解码字符串
- Master slave synchronization of MySQL database to realize read-write separation
- 拼多多店铺搜索相关问题,为什么新品上架搜索不到
- Dynamic programming -- gliding wing of the strange thief Kidd
- 飞升:基于中文分词器IK-2种自定义热词分词器构建方式showcase & 排坑showtime
- Cisco VXLAN配置
- 1380. lucky numbers in matrices
- Variable parameters of go
- [ansible series] fundamentals -01
- UE4_ Editor UMG close window cannot destroy UMG immediately
猜你喜欢
Using lazy < t > in C # to realize singleton mode in WPF
MySQL存储系统
MySQL数据库用户管理
Feisheng: Based on the Chinese word breaker ik-2 ways to build custom hot word separators Showcase & pit arrangement Showtime
云服务器部署 Web 项目
Swoole process model diagram
Do you know how to show the health code in only 2 steps
Here comes the nearest chance to Ali
Mysql database learning notes - foreign keys, table connections, subqueries, and indexes for MySQL multi table queries
[OSPF] comparison between rip and OSPF
随机推荐
Xctf attack and defense world crypto advanced area
STM32F103 series controlled OLED IIC 4-pin
Idea of capturing mobile terminal variant combination
网络基础知识
After getting these performance test decomposition operations, your test path will be more smooth
Prototype and prototype chain in JS
Talking about the struct of go
Projet Web de déploiement du serveur Cloud
24、 I / O device model (serial port / keyboard / disk / printer / bus / interrupt controller /dma and GPU)
At the beginning of 2022, people who are ready to change jobs should pay attention to
Lantern Festival | maoqiu technology and everyone "guess riddles and have a good night"
Zibll子比主题V6.4.1wordpress 开心版源码下载_破解原版/直接使用/无需教程
Turn off automatic outlining in Visual Studio - turning off automatic outlining in Visual Studio
飞升:基于中文分词器IK-2种自定义热词分词器构建方式showcase & 排坑showtime
Solidy - fallback function - 2 trigger execution modes
luoguP2756 飞行员配对方案问题(最大流)
雲服務器部署 Web 項目
[ansible series] fundamentals 02 module debug
09- [istio] istio service entry
[Alibaba cloud] student growth plan answers