フィルターのクリア

jsonencode not right format

8 ビュー (過去 30 日間)
Pete sherer
Pete sherer 2023 年 4 月 13 日
回答済み: the cyclist 2023 年 4 月 13 日
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 件)

カテゴリ

Help Center および File ExchangeJSON Format についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by