Sorting JSON by value.

polaris · · 521 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>So I&#39;m making an API which logs a lot of different data. I would like to have a function that calls all data that includes an specific IP for example. However I&#39;ve hit a stone wall atm and I don&#39;t know how to proceed. This is an example of one JSON object I have:</p> <p>{ ip: &#34;192.168.2.1&#34;, id: 1, time: &#34;0001-01-01T00:00:00Z&#34;, smethod: &#34;This is Method&#34;, level: &#34;Level 1&#34;, data: &#34;This is data&#34; },</p> <p>. Lets say I have 10 objects like this but 3 with the same IP. How would I make a function that only shows the 3 with the same IP?</p> <hr/>**评论:**<br/><br/>absdevops: <pre><p>Hi buddy - gave it a go, just left it in function main for you to play about it with and seperate it into a seperate function as you wish:</p> <p><a href="https://gist.github.com/arehmandev/818b0c54f4d12db296ab21c2475e5ac0" rel="nofollow">https://gist.github.com/arehmandev/818b0c54f4d12db296ab21c2475e5ac0</a></p> <p>edit - updated with a 2nd file to show you how it can be seperated. For each JSON object you just need to create a new &#39;Dataset&#39; object and append it to a slice of []Dataset.</p></pre>JonTargaryanTheFirst: <pre><p>Thank you! True lifesaver!!</p></pre>gbitten: <pre><ul> <li><a href="https://golang.org/pkg/encoding/json/" rel="nofollow">https://golang.org/pkg/encoding/json/</a></li> <li><a href="https://blog.golang.org/json-and-go" rel="nofollow">https://blog.golang.org/json-and-go</a></li> </ul></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

521 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传