Closed jacobkyhsu closed 3 years ago
json_unpack(root, "{s?i}", "64bit", &bit64_value);
You should use I
instead of i
for json_unpack.
From https://jansson.readthedocs.io/en/2.13/apiref.html#parsing-and-validating-values:
i (integer) [int]: Convert a JSON integer to C int.
(always 4 bytes)I (integer) [json_int_t]: Convert a JSON integer to C json_int_t.
For the case with i
json_unpack tries to store sizeof(int)
bytes to your pointer: https://github.com/akheron/jansson/blob/master/src/pack_unpack.c#L715-L744
Hi,
when i decode 64 bits integer via json_unpack api, i got a incorrect value, the return value is only 32 bits. so i use another method to get 64 bits integer via json_integer_value, the return value is correct. does json_unpack support to decode 64 bits integer?
follows is my test code.
include
include
include
include "jansson.h"
include "jansson_config.h"
const char data="{\"64bit\":9223372036854775807}"; void main(){ json_t root; json_error_t error; const char key; json_t value; json_int_t bit64_value =0;
}
the execute result is as follows: INT64_MAX=9223372036854775807 print1: bit64_value=4294967295 print2: bit64_value = 9223372036854775807
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
is there any problem in my test code? or json_unpack does not support to decode 64 bits integer?