当前位置:网站首页>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
边栏推荐
- Dynamic programming -- gliding wing of the strange thief Kidd
- Configure the user to log in to the device through telnet -- AAA local authentication
- Golang's handwritten Web Framework
- 880. 索引处的解码字符串
- [Alibaba cloud] student growth plan answers
- 86. separate linked list
- 【学习强化学习】总目录
- [GPU] basic operation of GPU (I)
- How to print pthread_ t - How to print pthread_ t
- 云服务器部署 Web 项目
猜你喜欢

We strongly recommend more than a dozen necessary plug-ins for idea development

MySQL事物

电脑查看WiFi使用密码

Intelligent deodorizer embedded development

Configure the user to log in to the device through telnet -- AAA local authentication

STM32F103系列控制的OLED IIC 4针

Cisco vxlan configuration

Dynamic programming -- gliding wing of the strange thief Kidd

Switch to software testing and report to the training class for 3 months. It's a high paying job. Is it reliable?

Official win 10 image download
随机推荐
Shenzhou ares tx6 boot logo modification tutorial
Create uiactionsheet [duplicate] - creating uiactionsheet [duplicate]
Sound network, standing in the "soil" of the Internet of things
Today, Ali came out with 35K. It's really sandpaper that wiped my ass. it showed me my hand
ES6箭头函数
[regular expression series] greedy and non greedy patterns
One sentence introduction to Trojan horse
Leetcode56. consolidation interval
MySQL index
Create priority queue
Talking about the struct of go
Share problems solved
At the beginning of 2022, people who are ready to change jobs should pay attention to
ES6扩展运算符(...)
UE4_ Editor UMG close window cannot destroy UMG immediately
Set of XXL job principles
Mysql database user management
Inno setup the simplest user-defined interface effect
[openstack]-01- basic introduction
requests. The difference between session () sending requests and using requests to send requests directly