如何在 Perl 中循环 json 结果
我正在尝试从访问 mysql 数据库的 perl 脚本输出 JSON。
如何循环查询返回并使用 JSON 模块将其转换为 JSON?
当我这样做时,我得到的只是 1 个返回
while($query_handle->fetch()) {
$jsonStructure->{event};
$jsonStructure->{event}->{evid} = $evid;
$jsonStructure->{event}->{component} = $component;
$jsonStructure->{event}->{firstTime} = $firstTime;
$jsonStructure->{event}->{lastTime} = $lastTime;
$jsonStructure->{event}->{count} = $count;
$jsonStructure->{event}->{summary} = $summary;
$jsonStructure->{event}->{severity} = $severity;
}
基本上我有很多事件并且不知道怎么说 event[0]...
谢谢
I am trying to output JSON from a perl script that accesses a mysql database.
How I can I loop through my query returns and turn that into JSON using the JSON module?
When I do this all I get is 1 return
while($query_handle->fetch()) {
$jsonStructure->{event};
$jsonStructure->{event}->{evid} = $evid;
$jsonStructure->{event}->{component} = $component;
$jsonStructure->{event}->{firstTime} = $firstTime;
$jsonStructure->{event}->{lastTime} = $lastTime;
$jsonStructure->{event}->{count} = $count;
$jsonStructure->{event}->{summary} = $summary;
$jsonStructure->{event}->{severity} = $severity;
}
Basically I have many events and don't know how to say event[0]...
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你正在寻找的是这样的:
尽管即使这样也可能有点过头了,因为你可能可以这样做:
如果数据库中的所有列名与 JSON 中你想要的字段名相同,并且你想要所有列,或者:
如果您只想要某些列,或者:
对于完全任意的映射。 Perl 的力量等等。 :)
I think what you're looking for is this:
although even that is probably overkill, because you can probably do something like:
if all of the column names in the DB are the same as the field names you want in the JSON, and you want all columns, or:
if you only want some columns, or:
for a completely arbitrary mapping. Power of Perl and all that. :)