<p>So I'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've hit a stone wall atm and I don't know how to proceed. This is an example of one JSON object I have:</p>
<p>{
ip: "192.168.2.1",
id: 1,
time: "0001-01-01T00:00:00Z",
smethod: "This is Method",
level: "Level 1",
data: "This is data"
},</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 'Dataset' 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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传