当前位置:网站首页>2022-07-20:以下go语言代码是关于json 和 context的,输出什么?A:{};B:{“a“:“b“};C:{“Context“:0};D:不确定。 package main imp
2022-07-20:以下go语言代码是关于json 和 context的,输出什么?A:{};B:{“a“:“b“};C:{“Context“:0};D:不确定。 package main imp
2022-07-21 00:34:00 【福大大架构师每日一题】
2022-07-20:以下go语言代码是关于json 和 context的,输出什么?A:{};B:{“a”:“b”};C:{“Context”:0};D:不确定。
package main
import (
"context"
"encoding/json"
"fmt"
)
func main() {
data, _ := json.Marshal(context.WithValue(context.Background(), "a", "b"))
fmt.Println(string(data))
}
答案2022-07-20:
答案选C。WithValue 底层是 valueCtx 结构体,其中 key、val 两个字段未导出,这里存放 “a” 和 “b”,同时还内嵌了 Context 接口。根据 Marshal 的规则,非导出的不会被序列化。而内嵌 Context 相当于导出了 Context 字段,而它的值是 context.Background(),即 background = new(emptyCtx),emptyCtx 实际是 int 类型,因此选 C。
边栏推荐
- Redis practice (I) login
- Yolox ---- human doubts!
- How to use sketch to design web pages and create grid guides tutorial
- Vite 配置 cdn 加载资源
- Meaning of downstream task
- In the code free era, how should enterprises' digital transformation develop?
- More and more scenes and industries begin to be related to the metauniverse
- New research of Stanford and meta AI: Data pruning is more important than we think on the road to AgI
- Digital marketing has become a trend for small programs to break the situation
- 越来越多的场景和行业开始与元宇宙扯上关系
猜你喜欢
The most complete summary of MySQL data types in history - (first)
[CS231N]Notes_ 1-Introduction
简单了解---JVM
狂神redis笔记05
Crazy God redis notes 05
Configuring Kali under VMware (I)
Ue4gameplay framework
Pictures used in network counting
Mobilevit: challenge the end-to-side overlord of mobilenet
Sycl learning notes
随机推荐
Explain cache penetration, cache avalanche, cache breakdown
Qdu summer training first week limited time training 1
gdb使用详细介绍
212. 单词搜索 II
Prevent duplicate insert data in SQLite
C language compilation
Ros2 introductory tutorial | action communication and user-defined interface
About web responsive design
Atomicinteger explanation
Memories of the final examination of information security of the Department of software
【OpenCV】solvePnPRansac /solvePnP 计算外参数,求解相机位姿
leetcode:1125. 最小的必要团队【状压dp板子 + 集合覆盖板子】
视频36 13章
看懂RTK定位,这一篇就够啦!
redis 实践(一)实现登录
@The difference between document annotation and Lombok
动态内存管理
聊聊10种延迟任务
Simple understanding -- JVM
Dynamic memory management