Thomas Elsgaard
2011-12-10 16:22:57 UTC
Hi CPH.pm
I am struggling a little with storing a mysql result set into a JSON object.
Which requires a data structure like this:
my $data = [
{
'servers' => [
{
'DateTime' => '2011-11-13 13:04:00',
'TotalNumberOfUsersRegistered' => '1205.00'
},
{
'DateTime' => '2011-11-13 13:00:00',
'TotalNumberOfUsersRegistered' => '1205.00'
}
]
}
];
Any good suggestions for how i can get the result set from my data
fetch routine below, into a data structure like the one above, in a
"pretty way" ?
#####################
while(my $ref = $sth->fetchrow_hashref()) {
print "DateTime: $ref->{'DateTime'}\n";
print "TotalNumberOfUsersRegistered: $ref->{'TotalNumberOfUsersRegistered'}\n";
}
#####################
The end result should be a JSON object like this:
[{"TotalNumberOfUsersRegistered":"1205.00","DateTime":"2011-11-13
13:04:00"},{"TotalNumberOfUsersRegistered":"1205.00","DateTime":"2011-11-13
13:00:00"}]
Best regards
///Thomas
I am struggling a little with storing a mysql result set into a JSON object.
Which requires a data structure like this:
my $data = [
{
'servers' => [
{
'DateTime' => '2011-11-13 13:04:00',
'TotalNumberOfUsersRegistered' => '1205.00'
},
{
'DateTime' => '2011-11-13 13:00:00',
'TotalNumberOfUsersRegistered' => '1205.00'
}
]
}
];
Any good suggestions for how i can get the result set from my data
fetch routine below, into a data structure like the one above, in a
"pretty way" ?
#####################
while(my $ref = $sth->fetchrow_hashref()) {
print "DateTime: $ref->{'DateTime'}\n";
print "TotalNumberOfUsersRegistered: $ref->{'TotalNumberOfUsersRegistered'}\n";
}
#####################
The end result should be a JSON object like this:
[{"TotalNumberOfUsersRegistered":"1205.00","DateTime":"2011-11-13
13:04:00"},{"TotalNumberOfUsersRegistered":"1205.00","DateTime":"2011-11-13
13:00:00"}]
Best regards
///Thomas