Skip to content

Commit

Permalink
saving JSON with UTF-8 encoding, fix #71
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jun 11, 2023
1 parent a3c807f commit 5135dea
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions savejson.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
% compressed binary array data.
% CompressArraySize [100|int]: only to compress an array if the total
% element count is larger than this number.
% CompressStringSize [400|int]: only to compress a string if the total
% CompressStringSize [inf|int]: only to compress a string if the total
% element count is larger than this number.
% FormatVersion [3|float]: set the JSONLab output version; since
% v2.0, JSONLab uses JData specification Draft 1
Expand Down Expand Up @@ -152,7 +152,7 @@
opt.singletarray = jsonopt('SingletArray', 0, opt);
opt.formatversion = jsonopt('FormatVersion', 3, opt);
opt.compressarraysize = jsonopt('CompressArraySize', 100, opt);
opt.compressstringsize = jsonopt('CompressStringSize', opt.compressarraysize * 4, opt);
opt.compressstringsize = jsonopt('CompressStringSize', inf, opt);
opt.intformat = jsonopt('IntFormat', '%.0f', opt);
opt.floatformat = jsonopt('FloatFormat', '%.16g', opt);
opt.unpackhex = jsonopt('UnpackHex', 1, opt);
Expand Down Expand Up @@ -248,6 +248,10 @@
json = sprintf('%s(%s);%s', jsonp, json, nl);
end

if(jsonopt('UTF8', 1, opt) && exist('unicode2native'))
json= unicode2native(json);
end

% save to a file if FileName is set, suggested by Patrick Rapin
filename = jsonopt('FileName', '', opt);
if (~isempty(filename))
Expand Down

0 comments on commit 5135dea

Please sign in to comment.