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