jsonencode not right format

3 次查看(过去 30 天)
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
}"

采纳的回答

the cyclist
the cyclist 2023-4-13
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 }"

更多回答(0 个)

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by