JS.ToArray(Response.ResultAsObject['value'])

I use this quite a lot in my Async calls, but for some reason I have a particular instance where it just returns null.

var
lParams: JS.TJSAraay;
Response: TXDataClientResponse;
begin
  lResponse := await(TXDataClientResponse,  MainData.WebClient.RawInvokeAsync(IREPORT_SVC_FETCHPARAMS, [ARecordId]));

lParams := JS.ToArray(lResponse.ResultAsObject['value']);

//....
end;

The response Result is:

FResult:
value: "[{\"ParamName\":\"LASTNAME\",\"SQLName\":\"\",\"DisplayName\":\"Lastname\",\"LocalType\":\"\",\"ParamType\":24,\"ParamOperator\":0,\"ParamValueType\":0,\"RefCount\":2}]"

[{"ParamName":"LASTNAME","SQLName":"","DisplayName":"Lastname","LocalType":"","ParamType":24,"ParamOperator":0,"ParamValueType":0,"RefCount":2}]"
Any ideas?

Is this something specific to your data, or do you mean that you can request the same ARecordId and sometimes it returns no data?

Does your endpoint return a String? Would it be better if it was a stream or some other format so that the data returned doesn't have all the extra escaped quotes in it?

The data is always correctly returned. It's just that the call to JS.ToArray returns null in this instance.

Maybe a stream might be worth a try. Can't see why it is working elsewhere though.

Not sure. In JS I passed your FResult value through JSON.parse and it came out as an array just fine. Maybe try that instead of the ToArray call?

Excellent. That worked. Saved a bit of recoding back end. Thanks @AndrewSimard

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.