|
159 | 159 | txt=struct2json(name,item,level,varargin{:}); |
160 | 160 | elseif(ischar(item)) |
161 | 161 | txt=str2json(name,item,level,varargin{:}); |
| 162 | +elseif(isobject(item)) |
| 163 | + txt=matlabobject2json(name,item,level,varargin{:}); |
162 | 164 | else |
163 | 165 | txt=mat2json(name,item,level,varargin{:}); |
164 | 166 | end |
|
411 | 413 | end |
412 | 414 | txt=sprintf('%s%s%s',txt,padding1,'}'); |
413 | 415 |
|
| 416 | +%%------------------------------------------------------------------------- |
| 417 | +function txt=matlabobject2json(name,item,level,varargin) |
| 418 | +if numel(item) == 0 %empty object |
| 419 | + st = struct(); |
| 420 | +else |
| 421 | + % "st = struct(item);" would produce an inmutable warning, because it |
| 422 | + % make the protected and private properties visible. Instead we get the |
| 423 | + % visible properties |
| 424 | + propertynames = properties(item); |
| 425 | + for p = 1:numel(propertynames) |
| 426 | + for o = numel(item):-1:1 % aray of objects |
| 427 | + st(o).(propertynames{p}) = item(o).(propertynames{p}); |
| 428 | + end |
| 429 | + end |
| 430 | +end |
| 431 | +txt=struct2json(name,st,level,varargin{:}); |
| 432 | + |
414 | 433 | %%------------------------------------------------------------------------- |
415 | 434 | function txt=matdata2json(mat,level,varargin) |
416 | 435 |
|
|
0 commit comments