<p>This may be an issue with my understanding of how to decode the JSON output of <code>go list -json</code>, but I would expect that if the result included multiple packages, the resulting JSON would be an array of objects. In fact, it's just consecutive JSON objects.</p>
<pre><code>$ ~ go version
go version go1.5 darwin/amd64
$ ~ go list github.com/gorilla/...
github.com/gorilla/context
github.com/gorilla/handlers
github.com/gorilla/mux
...
$ MH01936533MACLT ~ go list -json github.com/gorilla/...
{
...
"ImportPath": "github.com/gorilla/context",
"Name": "context",
...
}
{
...
"ImportPath": "github.com/gorilla/handlers",
"Name": "handlers",
...
}
{
...
"ImportPath": "github.com/gorilla/mux",
"Name": "mux",
...
}
...
</code></pre>
<p>Is this easily unmarshalled using the <code>encoding/json</code> package? Thanks!</p>
<hr/>**评论:**<br/><br/>farmingyaks: <pre><p>You can use json.Decoder to decode multiple objects, e.g.</p>
<p><code>
dec := json.NewDecoder(os.Stdin)
for {
value := map[string]interface{}{}
err := dec.Decode(&value)
if err != nil {
break
}
}
</code></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传