Why does jsonencode parser does not remove exponential notations when format longG is used?
이전 댓글 표시
I would like to save a structured data in a JSON file. There are various structured array elements that has integer number that needs to be represented without any exponents in the notation.
The following is an example commands that formats correctly as per my requirement on command window. But formats with exponent notation after saving to a json file.
Example:
% Command Window output
>> clear all
>> format long g
>> university.department.EEE.studentID = {122323259857567}
university =
struct with fields:
department: [1x1 struct]
>> university.department.EEE.studentID
ans =
1x1 cell array
{[122323259857567]}
% When I write it to JSON File the cell array now saves the above studentID with exponents
>>jsonData = jsonencode(university);
saveFileName = [filePath, '/', 'student1.json'];
fileId = fopen(saveFileName, 'w');
if fileId== -1, error('Cannot create JSON file');end
fwrite(fileId, jsonData, 'char');
fclose(fileId);
% student1.json now has :
% {
% "department":
% "EEE": {
% studentID: {[1.223232598575670e+14]}
% studentName: "XYZ YUI"
%
% }
% "ECE":{
% studentID: {[1.223232598575670e+14]}
% studentName: "sdf YUI"
%
% }
% "CS":{
% studentID: {[1.223232598575670e+14]}
% studentName: "ABC YUI"
% }
% }
%
%
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 JSON Format에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!