美文网首页
不使用 struct 定义 json 字符串

不使用 struct 定义 json 字符串

作者: xcyzjs | 来源:发表于2021-09-01 09:07 被阅读0次
// 方法一: 生写 string
jsonStr := `
"name": "Jack",
"age": 25
`

// 方法二: map[string]interface{}
jsonMap := map[string]interface{}{
  "name": "Jack",
  "age": 66,
}
jsonByte, _ = json.Marshal(jsonMap)
jsonStr = string(jsonByte)




另外 jsonStr 转 io.Reader
r := strings.NewReader(jsonStr)

相关文章

网友评论

      本文标题:不使用 struct 定义 json 字符串

      本文链接:https://www.haomeiwen.com/subject/pfhxwltx.html