我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

JSON中的转义逗号

http://play.golang.org/p/lF2ZgAyxei

How do I escape comma in JSON tag in Go?

type AA struct {
  MyStr string `json:"sub,ject"`
}

func main() {
  jsonStr := `
  {
    "sub,ject":         "I"
  }
  `
  stt := new(AA)
  json.Unmarshal([]byte(jsonStr), stt)
  fmt.Println(stt)

  t, _ := strconv.Unquote(jsonStr)
  fmt.Println(t)
}

This does not grab the key and only returns empty results.

How do I escape the comma?

The code used by the JSON encoding package to parse field tags is in tags.go. This code splits the field name from the options at the first comma. It not possible to escape the comma.

近期文章

  • 使用`json:“,string“`返回无效使用,string struct标签,试图解组未引用的值
  • Go:函数回调返回接口的实现
  • 如何使用<-chan和chan <-进行单向通信?
  • Go中的多维切片
  • 未选择Golang MySQL数据库
  • 我怎么知道必须关闭?
  • 如何在Go中执行类似numpy的arange的操作?
  • 在Go中为map [string] interface {}创建方法
  • Golang与PHP https调用的标头结果不同
  • 基础的C语言小问题,定义函数
  • 调用子函数时怎样往子函数里赋值?
  • vm虚拟机安装的Mac Os 系统怎么开启vt
  • 在方法中初始化nil指针结构
  • 如何从Go中的标准输入扫描big.Int
  • 我可以在Go中使用共享对象吗?
  • 什么时候关闭文件?
  • Go中扩展类型的访问方法
  • 在golang中输入文件
  • 为什么Go的Martini的性能不如Play Framework 2.2.x
  • 可重新配置的功能变量

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华