add jdataencode and jdatadecode · NeuroJSON/jsonlab@95b2eb0 · GitHub
Skip to content

Commit 95b2eb0

Browse files
author
Qianqian Fang
committed
add jdataencode and jdatadecode
1 parent f86219d commit 95b2eb0

5 files changed

Lines changed: 40 additions & 12 deletions

File tree

struct2jdata.m renamed to jdatadecode.m

Lines changed: 6 additions & 6 deletions

‎jdataencode.m‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function newdata=jdataencode(data,varargin)
2+
%
3+
% newdata=jdataencode(data,opt,...)
4+
%
5+
% encode special MATLAB objects (cells, structs, sparse and complex arrays,
6+
% maps, graphs, function handles, etc) to the JData format
7+
%
8+
% authors:Qianqian Fang (q.fang <at> neu.edu)
9+
%
10+
% input:
11+
% data: a matlab object
12+
% opt: (optional) a list of 'Param',value pairs for additional options.
13+
% For all supported options, please see the help info for savejson.m
14+
% and loadjson.m
15+
%
16+
% output:
17+
% newdata: the covnerted data containing JData structures
18+
%
19+
% examples:
20+
% jd=jdataencode(struct('a',rand(5)+1i*rand(5),'b',[],'c',sparse(5,5)))
21+
%
22+
% license:
23+
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
24+
%
25+
% -- this function is part of JSONLab toolbox (http://iso2mesh.sf.net/cgi-bin/index.cgi?jsonlab)
26+
%
27+
28+
newdata=loadjson(savejson('',data,varargin{:}),varargin{:},'JDataDecode',0);

‎loadjson.m‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ function parse_char(inputstr, c)
413413
end
414414
end
415415
parse_char(inputstr, '}');
416-
if(isstruct(object))
417-
object=struct2jdata(object,struct('Recursive',0));
416+
if(isstruct(object) && jsonopt('JDataDecode',1,opt)==1)
417+
object=jdatadecode(object,struct('Recursive',0));
418418
end
419419
end
420420

@@ -517,4 +517,4 @@ function error_pos(msg, inputstr)
517517
obj=reshape(obj,nextdim,numel(obj)/nextdim)';
518518
nextidx=length(arraystr)+1;
519519
end
520-
end
520+
end

‎loadmsgpack.m‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
data=data{1};
3434
end
3535
if(iscell(data))
36-
data=cellfun(@(x) struct2jdata(x),data,'UniformOutput',false);
36+
data=cellfun(@(x) jdatadecode(x),data,'UniformOutput',false);
3737
elseif(isstruct(data))
38-
data=struct2jdata(data);
38+
data=jdatadecode(data);
3939
end
4040
end
4141

‎loadubjson.m‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)