Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Getting error while decoding JSON object via POST method

by Corion (Pope)
on Feb 06, 2013 at 07:25 UTC ( #1017350=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Getting error while decoding JSON object via POST method
in thread Getting error while decoding JSON object via POST method

Have you printed out your JSON data string at the receiving end to see what you get there? An empty string gives the same error message:

>perl -MJSON -e "print JSON->new->decode('')" malformed JSON string, neither array, object, number, string or atom, +at character offset 0 (before "(end of string)") at -e line 1.

I think you are trying to pass the data around in a very bad manner:

<c> "/projectname/restfulapi?inputdata=$jsonData"; <c>

If you send POST data, please read HTTP::Request on how to send POST data. If you want to send the data in an URI, please encode it properly using URI::Encode.


Comment on Re^3: Getting error while decoding JSON object via POST method
Download Code
Re^4: Getting error while decoding JSON object via POST method
by perlCrazy (Monk) on Feb 06, 2013 at 08:40 UTC
    mo luck!! tried like this:
    my $inData = { "name" => "test", "id" => "test", "test" => [1,2,3,4],} +; my $json = JSON->new->utf8->allow_nonref; my $jsonData = $json->encode($inData); print Dumper($jsonData); ##Output of dumper : $VAR1 = '{"test":[1,2,3,4],"name":"test","id":"test"}'; # post set post request my $req = HTTP::Request->new('POST', $rest_url); $req->content($jsonData); my $response = $iua->request($req);
    getting same error.

      Where did you try what?

      I think that you are either not sending the data you think you're sending, or you're not receiving the data you think you're receiving. You have not shown working, self-contained code that exhibits the problem, so it's hard to replicate your problem or to understand what you're doing wrong.

      If you want to investigate this further, I suggest printing the values you get in the request to a log file on the receiving end.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-09-17 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls