{ @sendArray } won't do what you want because you're putting the array inside a
hash reference.
You either want to put it inside an array ref, or reference it, e.g.
[
@sendArray
]
or just \@sendArray.
Of course you could also do:
{
results => \@sendArray
}
if you want your output to be a hash at the top level.
Hope this helps!
--
Rik Brown
http://www.rikbrown.co.uk/
On Saturday, 6 July 2013 at 16:28, Anand Meher wrote:
> Dear dancer experts,
> I have a 1D Perl array which I would like to
> encode using JSON and send it as a response to an ajax request.
>
> I have implemented the following steps so far in my dancer app:
>
> use Dancer::Plugin::Ajax;
> set serializer => 'JSON';
>
> ajax '/getarray' => sub {
>
> my @sendArray;
> ...........
> {
> @sendArray; # this is the array I intend to send to the client Java
> Script
> }
>
> };
>
>
> The sendArray is not a (key, value) pair based structure, but a simple 1D
> array.
> Can anyone let me know if "@sendArray" statement at the end of ajax
> routine above will correctly encode to JSON?
>
> Also is there any way to print (to console) the final encoded JSON object
> from the ajax routine at the server end?
>
> thanks in advance
> \amk
>
>
> _______________________________________________
> dancer-users mailing list
> [email protected] (mailto:[email protected])
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
>
_______________________________________________
dancer-users mailing list
[email protected]
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users