<p>I was wondering what is most efficient (not wasting memory) and fastest way to download a JSON file and parse it.</p>
<p>I looked into the json.Decoder but are they any other solutions out there?</p>
<p>Thanks in advance.</p>
<hr/>**评论:**<br/><br/>raff99: <pre><p>Assuming your JSON file is large because it contains long list of objects, you do something like this:</p>
<p><a href="https://golang.org/pkg/encoding/json/#example_Decoder_Decode_stream" rel="nofollow">https://golang.org/pkg/encoding/json/#example_Decoder_Decode_stream</a></p>
<p>Basically you you find the beginning of the array using the streaming API and then use json.Decoder to decode the array elements one by one.</p></pre>dgryski: <pre><p>There are a number of third-party JSON decoders, with various trade-offs: <a href="https://github.com/pquerna/ffjson" rel="nofollow">https://github.com/pquerna/ffjson</a> , <a href="https://github.com/mailru/easyjson" rel="nofollow">https://github.com/mailru/easyjson</a> , but I would benchmark first to determine that json.Decoder isn't performing well enough before switching to one of them.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传