You are not logged in.
Pages: 1
Here is sample, RecordLoadJSON fail at "cost"
TR = packed record
errorId : Integer;
errorCode : String;
errorDescription : String;
status : String;
solution :
record
text : string;
url : string;
end;
cost : Double;
ip : String;
createTime : Integer;
endTime : Integer;
solveCount : Integer;
end;
....
var
R: TR;
s: string;
s:= '{"errorId":0,"status":"ready","solution":{"text":"failed","url":"http:\/\/69.39.239.233\/101\/147884423179984.png"},"cost":"0.001000","ip":"95.143.198.250","createTime":1478844231,"endTime":1478844239,"solveCount":"0"}';
SynCommons.RecordLoadJSON(R, s, TypeInfo(TR) );
Last edited by g00gle (2016-11-11 10:14:31)
Offline
This is working to me...
Two things :
1.- You are passing in JSON a (cost) Double variable like a string, this will not be parsed. Pass it without quotes.
2.- You are passing in JSON a (solveCount) Integer variable like a string, this will not be parsed. Pass it without quotes.
Look at your JSON and adapt it.
Last edited by turrican (2016-11-11 12:39:51)
Offline
turrican
This is not JSON from my side. :\
and every thing works if change double to string,
but i think it must work without this change.
Offline
turrican
This is not JSON from my side. :\
and every thing works if change double to string,
but i think it must work without this change.
So, where is crashing? Or where is the fault of the program?
Offline
Look at this :
Offline
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, SynCommons, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TR = packed record
errorId : Integer;
errorCode : String;
errorDescription : String;
status : String;
solution :
record
text : string;
url : string;
end;
cost : Double;
ip : String;
createTime : Integer;
endTime : Integer;
solveCount : Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
R: TR;
s: string;
begin
s:= '{"errorId":0,"status":"ready","solution":{"text":"failed","url":"http:\/\/69.39.239.233\/101\/147884423179984.png"},"cost":"0.001000","ip":"95.143.198.250","createTime":1478844231,"endTime":1478844239,"solveCount":"0"}';
SynCommons.RecordLoadJSON(R, s, TypeInfo(TR) );
Memo1.Lines.Add( R.errorId.ToString );
Memo1.Lines.Add( R.errorCode );
Memo1.Lines.Add( R.errorDescription );
Memo1.Lines.Add( R.status );
Memo1.Lines.Add( R.solution.text );
Memo1.Lines.Add( R.solution.url );
Memo1.Lines.Add( 'COST: ' + Format('%3.6f', [R.cost]) );
Memo1.Lines.Add( 'IP: ' + R.ip );
Memo1.Lines.Add( R.createTime.ToString );
Memo1.Lines.Add( R.endTime.ToString );
Memo1.Lines.Add( R.solveCount.ToString );
end;
Last edited by g00gle (2016-11-11 14:57:12)
Offline
Correct your JSON :
s:= '{"errorId":0,"status":"ready","solution":{"text":"failed","url":"http:\/\/69.39.239.233\/101\/147884423179984.png"},"cost":0.001000,"ip":"95.143.198.250","createTime":1478844231,"endTime":1478844239,"solveCount":0}';
Offline
2 turrican
read careful This is not JSON from my side. :\ http://synopse.info/forum/viewtopic.php … 303#p22303
Last edited by g00gle (2016-11-14 12:22:23)
Offline
So change your model to next one :
TR = packed record
errorId : Integer;
errorCode : String;
errorDescription : String;
status : String;
solution :
record
text : string;
url : string;
end;
cost : string;
ip : String;
createTime : Integer;
endTime : Integer;
solveCount : string;
end;
Offline
2 turrican
Are you seriously ?
I'm strongly recommend to you read my second post: http://synopse.info/forum/viewtopic.php … 303#p22303
Last edited by g00gle (2016-11-15 03:07:01)
Offline
And if you not agree that float can be readed from double quotes in case when we know that is it valid float then I'm not agree with you.
Offline
It doesn't matter if you agree, quoted strings are not doubles and the JSON definition is clear about it. It is up to you to use something like TryStrToFloat() with the given values to get your actual value. Perhaps use a secondary getter method or a intermediate class?
Offline
Pages: 1