Skip to content

Suggestion to solve the problem that variable is empty due to fix in #34 #45

@Hell3000

Description

@Hell3000

Suggestion to solve the problem that not empty string variables are saved empty due to fix in #34
:
Added the elseif with the matlab version check in savejson.m.

function txt=obj2json(name,item,level,varargin)

if(iscell(item))
    txt=cell2json(name,item,level,varargin{:});
elseif(isstruct(item))
    txt=struct2json(name,item,level,varargin{:});
elseif(ischar(item))
    txt=str2json(name,item,level,varargin{:});
elseif ~verLessThan('matlab','9.1') && isstring(item)
    % versions 2016b (9.1) and higher AND item is a string object
    % version check is necessary because function isstring existst only since 2016b

    % There's a new string class with " " syntax since 2016b (9.1) with the following characteristic:
    % isobject("String") returns true
    % isstring("String") returns true
    % ischar("String") returns false
    %
    % vs. character arrays with ' ' syntax:
    % isobject('chararr') returns false
    % isstring('chararr') returns false
    % ischar('chararr') returns true

    % Don't know if this is correct in every case:
    % convert string to char by: item{:}
    txt=str2json(name,item{:},level,varargin{:});
elseif(isobject(item)) 
    txt=matlabobject2json(name,item,level,varargin{:});
else
    txt=mat2json(name,item,level,varargin{:});
end

I didn't test with 2016b. Only with 2014b and 2017a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions