dsue14118 2016-12-03 17:01
浏览 969
已采纳

Go:JSON输入和JSON意外结束.Unmarshal返回nil值

I'm testing out how to unmarshal a json response from an API I'm using.

The json looks something like the following;

body := []byte(`[
    {"name":"Name1", "value":100.00},
    {"name":"Name2", "value":200.00}
]`)

I've searched around for various ways to do this, but fail to get this to work. The unmarshal returns zero values. I also get an error "unexpected end of JSON input" (I've removed the error handling in the example).

Full code example - https://play.golang.org/p/VMdWuAm6HS

Reference:

  1. https://godoc.org/encoding/json#RawMessage
  2. Golang json Unmarshal "unexpected end of JSON input"
  3. How to unmarshal json into interface{} in golang?
  • 写回答

1条回答 默认 最新

      报告相同问题?

      悬赏问题

      • ¥15 如何用LaTeX打出如下的表格
      • ¥15 程序填空补充完整的代码一共三题
      • ¥15 在MySQL中使用while建表,报错
      • ¥15 DB2线上告警,三表联查sql优化。
      • ¥15 python导入pyautogui报错,网上也没有找到解决方法如何解决?
      • ¥15 关于IPSEC和NAT SERVER同时使用的情况下,该如何解决客户端访问服务器的问题
      • ¥15 eclipse项目在idea运行部署到云服务器
      • ¥100 sql server image类型转换
      • ¥15 关于matlab的问题
      • ¥15 数据结构二叉树——统计二叉树的结点、深度、叶子结点个数