<p>Edit: Solved. I'm an idiot and didn't know I needed quotes.</p>
<p>So I'm having trouble getting this to work properly, hoping Reddit could help. I'm getting some JSON containing Weather info via the Wunderground API. It returns a whole lot of stuff but I'm only interested in various parts of it. In my testing I've had mixed results with getting things to unmarshal properly. <a href="https://play.golang.org/p/TwITkH8vAO" rel="nofollow">Playground Link</a> with an example of what's going on. In the first attempt, nothing is being unmarshalled, and in the second, only 1 value is unmarshalled. I'd like all the values in the struct to be populated, but the JSON contains much more information than what's in the struct</p>
<p>If anyone could give advice on what I'm doing wrong, I'd really appreciate it.</p>
<hr/>**评论:**<br/><br/>niosop: <pre><p>If you don't know about it, <a href="https://mholt.github.io/json-to-go/" rel="nofollow">https://mholt.github.io/json-to-go/</a> is handy as hell. Just paste in the whole JSON and it'll generate the go structs for you. Then you can delete the parts you don't care about.</p></pre>Guitarbum722: <pre><p>^ literally the best.</p></pre>popillol: <pre><p>Wow how did I not know about this, this is amazing. Thanks!</p></pre>JHunz: <pre><p>You need quotes around your field names inside the json tag, e.g. `json:"current_observation"`</p></pre>popillol: <pre><p>Oh man for some reason I didn't think those were necessary. Thanks for the help! I'm ashamed to say I had tried to figure out what was wrong for over an hour or two before asking Reddit</p></pre>TAAnderson: <pre><p>Maybe have a look at github.com/buger/jsonparser if you are only interested in some parts of the json.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传