|
173 | 173 | txt=str2json(name,item,level,varargin{:});
|
174 | 174 | elseif(isa(item,'string'))
|
175 | 175 | txt=str2json(name,item{:},level,varargin{:});
|
176 |
| -elseif(isobject(item)) |
177 |
| - txt=matlabobject2json(name,item,level,varargin{:}); |
| 176 | +elseif(isobject(item)) |
| 177 | + if(~exist('OCTAVE_VERSION','builtin') && istable(item)) |
| 178 | + txt=matlabtable2json(name,item,level,varargin{:}); |
| 179 | + else |
| 180 | + txt=matlabobject2json(name,item,level,varargin{:}); |
| 181 | + end |
178 | 182 | else
|
179 | 183 | txt=mat2json(name,item,level,varargin{:});
|
180 | 184 | end
|
|
434 | 438 |
|
435 | 439 | %%-------------------------------------------------------------------------
|
436 | 440 | function txt=matlabobject2json(name,item,level,varargin)
|
437 |
| -st = struct(); |
438 |
| -if numel(item) > 0 %non-empty object |
| 441 | +if numel(item) == 0 %empty object |
| 442 | + st = struct(); |
| 443 | +elseif numel(item) == 1 % |
| 444 | + st = struct(); |
| 445 | + txt = str2json(name, char(item), level, varargin(:)); |
| 446 | + return |
| 447 | +else |
439 | 448 | % "st = struct(item);" would produce an inmutable warning, because it
|
440 | 449 | % make the protected and private properties visible. Instead we get the
|
441 | 450 | % visible properties
|
|
448 | 457 | end
|
449 | 458 | txt=struct2json(name,st,level,varargin{:});
|
450 | 459 |
|
| 460 | +%%------------------------------------------------------------------------- |
| 461 | +function txt=matlabtable2json(name,item,level,varargin) |
| 462 | +if numel(item) == 0 %empty object |
| 463 | + st = struct(); |
| 464 | +else |
| 465 | + % "st = struct(item);" would produce an inmutable warning, because it |
| 466 | + % make the protected and private properties visible. Instead we get the |
| 467 | + % visible properties |
| 468 | + st = struct(); |
| 469 | + propertynames = properties(item); |
| 470 | + if(isfield(item.Properties,'RowNames') && ~isempty(item.Properties.RowNames)) |
| 471 | + rownames=item.Properties.RowNames; |
| 472 | + for p = 1:(numel(propertynames)-1) |
| 473 | + for j = 1:size(item(:,p),1) |
| 474 | + st.(rownames{j}).(propertynames{p}) = item{j,p}; |
| 475 | + end |
| 476 | + end |
| 477 | + else |
| 478 | + for p = 1:(numel(propertynames)-1) |
| 479 | + for j = 1:size(item(:,p),1) |
| 480 | + st(j).(propertynames{p}) = item{j,p}; |
| 481 | + end |
| 482 | + end |
| 483 | + end |
| 484 | +end |
| 485 | +txt=struct2json(name,st,level,varargin{:}); |
| 486 | + |
451 | 487 | %%-------------------------------------------------------------------------
|
452 | 488 | function txt=matdata2json(mat,level,varargin)
|
453 | 489 |
|
|
0 commit comments