当前位置:网站首页>Solution to null JSON after serialization in golang
Solution to null JSON after serialization in golang
2022-07-04 09:16:00 【The diligent bird that flies first】
type animal struct {
name string
age int
}
func main(){
ani := animal{
name: "lcq",
age: 23,
}
marshal, err := json.Marshal(ani)
if err != nil {
fmt.Println("err:", err)
return
}
fmt.Println(string(marshal))
}
The serialized result is :
{
}
The main reason is that the attribute is lowercase , External packages cannot be accessed , Just change the field name to uppercase .
type animal struct {
Name string
Age int
}
func main(){
ani := animal{
Name: "lcq",
Age: 23,
}
marshal, err := json.Marshal(ani)
if err != nil {
fmt.Println("err:", err)
return
}
fmt.Println(string(marshal))
}
边栏推荐
- Explain TCP protocol in detail three handshakes and four waves
- Awk from entry to earth (14) awk output redirection
- Jianzhi offer 09 realizes queue with two stacks
- Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
- awk从入门到入土(7)条件语句
- awk从入门到入土(8)数组
- The old-fashioned synchronized lock optimization will make it clear to you at once!
- [C Advanced] file operation (2)
- C语言-入门-基础-语法-[标识符,关键字,分号,空格,注释,输入和输出](三)
- 保姆级JDEC增删改查练习
猜你喜欢
26. Delete duplicates in the ordered array (fast and slow pointer de duplication)
After unplugging the network cable, does the original TCP connection still exist?
What exactly is DAAS data as a service? Don't be misled by other DAAS concepts
Implementation principle of redis string and sorted set
地平线 旭日X3 PI (一)首次开机细节
2022-2028 global special starch industry research and trend analysis report
2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
How to batch change file extensions in win10
Solve the problem of "Chinese garbled MySQL fields"
Sword finger offer 30 contains the stack of Min function
随机推荐
Trees and graphs (traversal)
Educational Codeforces Round 115 (Rated for Div. 2)
[error record] no matching function for call to 'cacheflush' cacheflush();)
Awk from getting started to digging in (4) user defined variables
[C Advanced] file operation (2)
Awk from entry to earth (14) awk output redirection
awk从入门到入土(5)简单条件匹配
The 14th five year plan and investment risk analysis report of China's hydrogen fluoride industry 2022 ~ 2028
Sequence model
Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
Reading notes on how to connect the network - hubs, routers and routers (III)
Leetcode topic [array] - 121 - the best time to buy and sell stocks
Global and Chinese market of bipolar generators 2022-2028: Research Report on technology, participants, trends, market size and share
Industry depression has the advantages of industry depression
UML sequence diagram [easy to understand]
C language - Introduction - Foundation - syntax - [variable, constant light, scope] (V)
The map set type is stored in the form of key value pairs, and the iterative traversal is faster than the list set
2022-2028 global tensile strain sensor industry research and trend analysis report
Research Report on the development trend and Prospect of global and Chinese zinc antimonide market Ⓚ 2022 ~ 2027