I get JSON from API and it have a quirk: usually it returns "tags" element as object {"x":"y"}, but if ther are no tags, it returns empty array [] instead.
I parse JSON with SuperObject, and use this code:
var
JsonObject: ISuperObject;
item: TSuperAvlEntry;
temp: TStringList;
begin
{...}
for item in JsonObject.O['tags'].AsObject do
begin
temp.Add(item.Name);
end;
{...}
It works wonderfully for objects, but it crashes with Access Violation error if it's an array.
As well, if I try something like:
if JSONObject['tags'].AsArray.Length=0 then
it works fine for empty array, but crashes if it is an object.
I don't know for sure that elements may be in "tags" and thus don't know how can I use Exists() in this case.
Any ideas?