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

Golang Unmarshal切片的int切片

How do you unmarshal a JSON into a slice of slices of ints? I keep on getting a blank struct: https://play.golang.org/p/Hgnh5C9FN_

Also is it possible to unmarshal something like [[1 2][3 4]] without a key e.g. {"key":[[1 2][3 4]]}?

It seems there is a three issues in your provided code snippet.

  • Struct field have to be exported, refer to Exported vs Unexported identifiers
  • Your JSON data is invalid invalid character '[' after array element {[]}
  • Field data type definition

I have updated your code here https://play.golang.org/p/zX7KEPKB8H

Output {[[1 2] [3 4]]}

近期文章

  • Golang,在Linux中加载Windows DLL
  • 如何使用sqlx进行LEFT JOIN查询?
  • 非常零星的Go HTTP错误:多个响应。WriteHeader调用
  • 在IntelliJ中导入Go项目不起作用
  • 解析Github的access_token响应
  • 如何在golang中找到(2,3或可能的话n)维切片的尺寸并验证其是否为矩阵?
  • 为什么goroutines没有`.join`操作?
  • Go具有模板语言吗?
  • 面向对象的实现
  • 去将reflect.Value从字符串转换为int
  • 错误的GET页面请求
  • 如何解决函数中的Go数组大小
  • 如何编写插入golang代码?
  • 将unicode字符存储在golang中
  • goroutine或多线程在golang中不起作用
  • 如何在Go中格式化此字符串
  • Archlinux:golang不能使用go build
  • 在GO中将字符串转换为函数名称? [重复]
  • 如何使用Golang在Linux中获得网络速度
  • 如何从Golang中的URL检索HTML文档大小

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华