How do I query a JSON array that is only with [] with XSuperObject

284 Views Asked by At

I have this array:

["a", "b", "c", "d"]

I need to get these results out using XSuperObject. Currently, from my understanding of the XSuperObject library, you would need something like this to get the data out:

aObj := SA(returnString);
for i := 0 to aObj.Length - 1 do
begin
  obj2 := aObj.O[i];
  arrayElement := GetJsonValue(obj2, keyValue);
end;

GetJSONValue is a function defined as:

function TfrmMain.GetJsonValue(obj:ISuperObject; Name: String): String; 
begin
  Result := '';
  if obj.Contains(Name) then
  Result := obj.S[Name];
end;

This work for an array that is returned in this JSON format:

[{"activityID":"1","keyValue":"a"},
 {"activityID":"2","keyValue":"b"},
 {"activityID":"3","keyValue":"c"}]

How would I get the XSuperObject library to work for the array at the top.

Any help would be greatly appreciated.

Thanks in advance.

1

There are 1 best solutions below

0
On

You have an array of strings, not an array of objects, so skip GetJsonValue() and use aObj.S[i] by itself:

aObj := SA(returnString);
for i := 0 to aObj.Length - 1 do
begin
  arrayElement := aObj.S[i];
end;