Filter löschen
Filter löschen

jsonencode not right format

8 Ansichten (letzte 30 Tage)
Pete sherer
Pete sherer am 13 Apr. 2023
Beantwortet: the cyclist am 13 Apr. 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
}"

Akzeptierte Antwort

the cyclist
the cyclist am 13 Apr. 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 }"

Weitere Antworten (0)

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by