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;
In reply to Int becomes String when I convert to json by bartender1382
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |