Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^10: json return value

by stenasc (Novice)
on Jul 16, 2013 at 14:01 UTC ( #1044608=note: print w/ replies, xml ) Need Help??


in reply to Re^9: json return value
in thread json return value

That worked, but need a slight change...

#!/usr/bin/env perl use strict; use warnings; use CGI; use CGI::Carp('fatalsToBrowser'); use JSON::PP(); my $q = CGI->new; print $q->header(), $q->start_html(-title=>"Hello World"), $q->h2("Hello World"), $q->end_html();


Comment on Re^10: json return value
Download Code
Re^11: json return value
by poj (Priest) on Jul 16, 2013 at 14:12 UTC
    Ok so try again with JSON::PP
    #!/usr/bin/env perl use strict; use warnings; use CGI (); use JSON::PP (); my $q = CGI->new; my $data = $q->param('POSTDATA') || '{"a":100,"b":300}'; my $json = JSON::PP->new->utf8; my $input = $json->decode( $data ); my $a = $input->{a}; my $b = $input->{b}; my $c = $a + $b; print $q->header("application/json"); print $json->encode({ c => $c });
    poj

      Fantastic. Thank you...now we're getting somewhere. When I loaded up the cgi in the browser, I get {"c":400}. Now just need to get the perl client working.

      It is finally working. Thank you to all the monks that replied and showed a great deal of patience. Couple of things causing the problems...

      The server was not set up correctly. Took a while for the administrator to accept this, but when he did, things started to work. It's frustrating when you are running round in circles, trying to tell these guys why it should be working and they're telling you something is wrong with your code, only to find out later that it was a server side issue.

      JSON was not allowed installed on the server as it was shared...dunno why. Had to use JSON::PP.

      I really do appreciate, the help and especially the code examples. This is an excellent forum and my faith has well and truly been restored.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1044608]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2014-12-18 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (67 votes), past polls