You are not logged in.
Pages: 1
This seems to be a bug with json parsing. Please try my code.
all fields are fine except bids that's every time is 0
type
TRL i= packed record
timestamp: integer;
asks : array of array[0..1] of string;
bids : array of array[0..1] of string;
end;
var s : UTF8String;
RLi: TRLi;
s:= quoted text below
.............
RecordLoadJSON(RLi, @s[1], typeinfo(TRLi) );
Caption := Length(RLi.asks).ToString + ':' + Length(RLi.bids).ToString; //208 : 0
..................
Last edited by skipjack (2018-01-29 15:07:49)
Offline
Check your json at least one online validator. https://jsonformatter.org/ https://codebeautify.org/jsonvalidator https://jsonlint.com/ You can see, that your data is not correct.
Last edited by Alek (2018-01-29 05:07:36)
Offline
Please DO NOT post such big amount of code or JSON in the forum!
Check the https://synopse.info/forum/misc.php?action=rules !
8)
Also note that array[0..1] kind of record type definition is not supported.
Use a dynamic array instead.
Then, as Alek stated, ensure that your input JSON is correct..
Offline
ab can you please explain why this happens:
Here is working type declaration for the code below :
type
TRLi = packed record
timestamp: string;
bids : array of array[0..1] of string;
asks : array of array[0..1] of string;
end;
And here is declaration that won't work:
type
TRLi = packed record
timestamp: string;
asks : array of array[0..1] of string;
bids : array of array[0..1] of string;
end;
both types are same, but RecordLoadJSON doesn't work with second Type as I expect
procedure TForm1.Button1Click(Sender: TObject);
var s : UTF8String;
RLi: TRLi;
begin
s:= '{"timestamp": "1","asks": [["2", "3"], ["4", "5"]],"bids": [["6", "7"], ["8", "9"], ["10", "11"]]}' ;
RecordLoadJSON(RLi, @s[1], typeinfo(TRLi) );
Caption := Length(RLi.asks).ToString + ':' + Length(RLi.bids).ToString; //2 : 3
end;
Last edited by skipjack (2018-01-29 17:56:28)
Offline
I can't understand what to do, may be spot of code will help me to understand.
if you mean use of asks : array of array of string; instead of asks : array of array[0..1] of string;
it doesn't work.
Last edited by skipjack (2018-01-29 20:43:38)
Offline
Maybe defining a record then an array would help
Offline
Pages: 1