bartender1382 has asked for the wisdom of the Perl Monks concerning the following question:
Below is my abbreviated code, which includes every line where I access or set an int value in a hash, before coding it into JSON then sending it out as an HTTP response/data.
The hash item, returnvalue, is an int. My code either returns a 7 or a 15.
When the code below sets returnvalue to 7 (SSSTAGE1), my Swift apps take the http data and decodes it with no problem.
When the code below sets returnvalue to 15 (SSCONVERTING), my Swift apps take the http data and gets a JSON type decoding error.
Further debugging in my Swift app shows that when set to 7 (SSSTAGE1) in the perl code below, the http data received shows:
returnvalue=>7, an int
Yet when returnvalue to 15 (SSCONVERTING), the http data shows:
returnvalue=>"15", a string
I know Perl can treat ints and strings interchangeably. So am curious if anyone has come across this before?
use enum qw( SSSUCCESS ... SSSTAGE1 ... SSCONVERTING ); use CGI; use JSON; local $SIG{CHLD} = "IGNORE"; my $q = new CGI; print $q->header(); my %out = ( username =>"", userid =>"", status =>"", filename =>"", rawfilename => "", ticket =>"", returnvalue => 0, message =>""); ... $out{returnvalue} = SSCONVERTING; ... if ($ticketinfo{status} == SSSTAGE1){ $out{returnvalue} = SSSTAGE1; } my $json = encode_json \%out; print $json; exit 0;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Int becomes String when I convert to json
by choroba (Cardinal) on May 09, 2022 at 19:28 UTC | |
by bartender1382 (Beadle) on May 10, 2022 at 02:02 UTC | |
by choroba (Cardinal) on May 10, 2022 at 07:23 UTC | |
by bartender1382 (Beadle) on May 10, 2022 at 16:23 UTC | |
by choroba (Cardinal) on May 10, 2022 at 20:18 UTC | |
| |
Re: Int becomes String when I convert to json
by Corion (Patriarch) on May 09, 2022 at 19:24 UTC | |
by Don Coyote (Hermit) on May 10, 2022 at 10:20 UTC | |
Re: Int becomes String when I convert to json
by Haarg (Priest) on May 10, 2022 at 00:25 UTC |