How to check if SuperObject is valid?

874 views Asked by At

When creating a SuperObject from a string, it might happen that the string is no valid JSon. Unfortunately the command SO doesn't raise an exception in that case. I end up with a object where I THINK I can store data in, but the "stored" data goes nowhere and is lost.

example:

 MySo:=SO('{}');
 MySO.S['ok']:='test';
 Memo1.Lines.Add(MySO.AsJSon(True, False));

 MySo:=SO('');
 MySO.S['fail']:='mimimi';
 Memo1.Lines.Add(MySO.AsJSon(True, False));  // returns '""' ??!??

How can I check if the string was converted successfully into a valid and working SuperObject?

1

There are 1 answers

1
ralfiii On

whorsyourdaddy's comment pointed into the right direction.

To be able to store INTO a JSon you need a stObject. You can check for that this way:

 if not MySo.IsType(stObject) then raise....