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

去:不能解组吗?

package main

import "fmt"
import "encoding/json"

func main() {
    m := make(map[string]string)
    m["name"] = "Test"

    j, _ := json.Marshal(m)

    fmt.Println(string(j))

    var unmarshalled map[string]string
    _ = json.Unmarshal(j, unmarshalled)
    fmt.Println(unmarshalled)
}

Shouldn't unmarshalled be filled with the json data j

Don't ignore your errors

json: Unmarshal(non-pointer map[string]string)

unmarshaled needs to be a pointer:

err := json.Unmarshal(j, &unmarshalled)

近期文章

  • 无法写入GeoJSON数据的集合
  • 从父函数返回子类型
  • 在切片中搜索字符串时找不到句柄
  • 导出结构仅用于Golang中的测试
  • 为什么CSP实施仅覆盖渠道?
  • 在这个例子中解释去生成
  • Go不能同时添加accept和content-type标头
  • 需要使用URL参数在Golang中查询Json数据
  • 为什么Go在base64编码中使用位运算?
  • 如何在Golang中获取以“ @”开头的json对象
  • 如何在golang中的字符串中获取错误消息?
  • 将JSON int解码为字符串
  • Go中的多态性-是否存在?
  • 从Go连接Oracle服务器上的数据库,而无需任何客户端
  • 如何导入自己的包?
  • Go程序的项目结构以在AWS Lambda上运行
  • Golang将哈希表转换为JSON
  • 从舵表中的值文件读取值时的默认键值
  • Golang中的AES加密和Java中的解密
  • Gos中具有非标准字段的结构数组上的MarshalJSON

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华