I have stumbeled accross an error that cought me totally by surprise, so I wanted to check with you if this makes sense...
Item := Songs.Items[Index] as TJSONObject;
ThisTrack := Item.Values['track'] as TJSONObject;
if (Assigned(ThisTrack)) then Begin;
End;
Songs
is a TJSONArray
, Item
and ThisTrack
are TJSONObject
.
If Item
does not contain a "track", the above code throws an ERangeError
exception on the 2nd line.
This is the first time I'm seeing this, and I am VERY sure, I had "NIL AS <something>" a lot in the past.
Is this a JSON-class specific issue?
Is the workaround for this really as follows?
ThisTrack: TJSONValue;
Item := Songs.Items[Index] as TJSONObject;
ThisTrack := Item.Values['track'];
If Assigned(ThisTrack) then Begin;
Tracks := (ThisTrack as TJSONObject).Values['uri'].Value);