I am a bit confused by the error I get when using my $decoded_json = decode_json( $json_text );. I retrieve $json_text with:
EDIT
use strict; use warnings; use LWP::UserAgent; use Data::Dumper; use JSON::PP; use HTTP::Request::Common; my $query = "research"; my $format = ""; my $domain = ""; my $language = ""; my $data = { query => $query, format => $format, domain => $domain, la +nguage => $language }; my $url = 'MyDomain/cgi-bin/querySearchEngine.pl'; my $ua = LWP::UserAgent->new; my $request = POST($url, Content_Type=>'application/json', Content => encode_json($data) ); my $response = $ua->request($request); if ($response->is_success) { my $json_text= $response->content; my $decoded_json = decode_json( $json_text ); }
My response $json_text (an array with a list of URI) looks like this:
{"myData":["https://www.sante.de/fileadmin/user_upload/Stellenanzeige_ +Mitarbeiter_Research__Development.pdf","https://www.national-bank.de/ +fileadmin/user_upload/nationalbank/Vermoegensmanagement/Research/Kapi +talmarkt_Studien/Kapitalmarktmonitor_Dezember_2018.pdf","https://www. +acxit.com/en/wp-content/uploads/2018/12/CAREERS_Stellenanzeige_WS_Res +earch_Deal_Generation_20181211.pdf","https://www.s-a.uni-muenchen.de/ +studierende/jobboerse/jobangebote/aktuelle/20181221_44.pdf","https:// +www.dbresearch.de/PROD/RPS_DE-PROD/PROD0000000000459596/Deutscher_H%C +3%A4user-_und_Wohnungsmarkt_2018.pdf","https://www.bayernlb.de/intern +et/media/de/ir/downloads_1/bayernlb_research/multiasset_produkte/Pers +pektiven.pdf","https://www.borders-in-motion.de/documents/12991/34723 +4/Flyer_Research_Factory_WS18-19.pdf/2baa6987-219a-4cbb-8ab0-da36754f +1282","https://deka.de/site/dekade_privatkunden_site/get/documents/de +kade/Publikationen/2018/Volkswirtschaft/Aktuell/20181220_VA_USA_Zinse +ntscheid.pdf","https://www.dmtm.com/medienverwaltung/medien/181218_Re +search_Engineer_Website.pdf","https://www.ewi.research-scenarios.de/c +ms/wp-content/uploads/2018/08/Czock_CV_de_20181214.pdf"]}
Server side EDIT
#!/usr/bin/perl use strict; use warnings; use CGI qw(:standard); use JSON; use utf8; use LWP::UserAgent; use HTTP::Request::Common; use Data::Dumper; my $q = CGI->new(); print $q->header; my $data = $q->param('POSTDATA'); $data = decode_json($data) if $data; my $query = $data->{'query'}; my $format = $data->{'format'}; my $domain = $data->{'domain'}; my $language = $data->{'language'}; my @UriCollected; print "Content-type: application/json;\n\n"; #performing crawling here and collecting uri in @UriCollected print objToJson( { myData => \@UriCollected } );
Error is:
malformed JSON string, neither array, object, number, string or atom, +at character offset 0 (before "Content-type: applic...") at
Error line my $decoded_json = decode_json( $json_text );
I use a similar way to exchange information in many cgi scripts with no problems. So I must be doing a very stupid error here... but I do not understand where...
In reply to json Array with URI by IB2017
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |