You are not logged in.
Pages: 1
Hi! There are a lot of such topics in the forum, however Im still a bit confused what is the best (fastest) way to parse an array!
In mORMot 2 I have used such approach:
var
x: Variant;
symbols: PDocVariantData;
begin
DoRequest('https://fapi.binance.com/fapi/v1/exchangeInfo');
obj := _Json(LastResponseA, JSON_OPTIONS_FASTMEM);
symbols := DocVariantData(obj.symbols);
for x in symbols.Values do sym := x.symbol;
However in mORMot 2 I have noticed in comments that length(Values)=Capacity so the code should look like
var
x: PVariant;
symbols: PDocVariantData;
begin
symbols := DocVariantData(obj.symbols);
for x in symbols.Items do sym := x^.symbol;
In this version we should use pointer to Variant, is it correct?
In other topics its recommened to use the _Safe procedure, however I didnt yet understand the reason... could you please clarify! Thanks !
Offline
The easiest is to NOT use variants, but TDocVariantData directly for x.
Or even easier, use a IDocDict instance.
Second method looks like this?
var x: Variant;
for x in DocList(_Safe(obj.symbols)^) do ;
First method I didnt understand, could you please give a hint... If I use
symbols := _Safe(obj.symbols);
then to iterate using .Items Enumerator, I need a PVariant?
Offline
Pages: 1