Borrar filtros
Borrar filtros

jsonencode not right format

8 visualizaciones (últimos 30 días)
Pete sherer
Pete sherer el 13 de Abr. de 2023
Respondida: the cyclist el 13 de Abr. de 2023
Hi
Is there a way to control behavior of jsonencode. Example below, I want the run_id to be full integer. However jsone encode writes it in floating format.
apiData = struct;
apiData.run_id = 1720787;
apiData.run = "BSCR_sbt rerun: PT Jan01_2023";
apiData.run_node_ids = [20970];
apiData.scale_load_factor = 1000.1;
if length( apiData.run_node_ids)== 1
apiData.run_node_ids = { apiData.run_node_ids};
end
jsonInp = string( jsonencode( apiData, 'PrettyPrint', true))
I got below, which the api doesn't accept float for run_id
jsonInp =
"{
"run_id": 1.720787E+6,
"run": "BSCR_sbt rerun: PT Jan01_2023",
"run_node_ids": [
20970
],
"scale_load_factor": 1000.001
}"

Respuesta aceptada

the cyclist
the cyclist el 13 de Abr. de 2023
Is it possible for you to store that number as an integer instead, for example
apiData.run_id = int64(1720787);
?
Because then
apiData = struct;
apiData.run_id = int64(1720787);
apiData.run = "BSCR_sbt rerun: PT Jan01_2023";
apiData.run_node_ids = [20970];
apiData.scale_load_factor = 1000.1;
if length( apiData.run_node_ids)== 1
apiData.run_node_ids = { apiData.run_node_ids};
end
jsonInp = string( jsonencode( apiData, 'PrettyPrint', true))
jsonInp =
"{ "run_id": 1720787, "run": "BSCR_sbt rerun: PT Jan01_2023", "run_node_ids": [ 20970 ], "scale_load_factor": 1000.1 }"

Más respuestas (0)

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by