-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON Serializing floating point properties. #704
Comments
Hi, can you show the code please? |
Hi! |
Any idea!? |
Very strange... I ran the compilation on a normal Windows 11. There it works, but on my Mac M2 with Parallels it does not work. It must have something to do with the operating system or Parallels. Any idea? |
Can you post the JSON contained in |
'{"error":false,"message":"","data":[{"id":101,"personId":4,"date":"2023-10-15T00:00:00Z","allowanceCatalogId":77,"allowanceSurchargeNo":"63","heavy":5,"workingHours":2.5,"createdAt":"2023-10-16T11:30:11Z","updatedAt":"2023-10-16T11:30:11Z"},{"id":102,"personId":4,"date":"2023-10-15T00:00:00Z","allowanceCatalogId":47,"allowanceSurchargeNo":"39","heavy":6,"workingHours":2.5,"createdAt":"2023-10-16T11:32:12Z","updatedAt":"2023-10-16T11:32:12Z"},{"id":105,"personId":4,"date":"2023-10-15T00:00:00Z","allowanceCatalogId":10,"allowanceSurchargeNo":"10","dirt":9,"workingHours":2.25,"createdAt":"2023-10-16T15:00:55Z","updatedAt":"2023-10-16T15:00:55Z"}]}' |
It really is a phenomenon. I have compiled the application for OSX ARM 64 and it works without problems. It must have something to do with Windows 11 ARM? |
I don't have a Windows 11 ARM machine, however the following code works as expected in Windows 11 with Win32 and with Win64 target. uses
JsonDataObjects;
{$R *.dfm}
procedure TForm13.Button1Click(Sender: TObject);
begin
var s := '{' +
' "error": false,' +
' "message": "",' +
' "data": [{' +
' "id": 101,' +
' "personId": 4,' +
' "date": "2023-10-15T00:00:00Z",' +
' "allowanceCatalogId": 77,' +
' "allowanceSurchargeNo": "63",' +
' "heavy": 5,' +
' "workingHours": 2.5,' +
' "createdAt": "2023-10-16T11:30:11Z",' +
' "updatedAt": "2023-10-16T11:30:11Z"' +
' }, {' +
' "id": 102,' +
' "personId": 4,' +
' "date": "2023-10-15T00:00:00Z",' +
' "allowanceCatalogId": 47,' +
' "allowanceSurchargeNo": "39",' +
' "heavy": 6,' +
' "workingHours": 2.5,' +
' "createdAt": "2023-10-16T11:32:12Z",' +
' "updatedAt": "2023-10-16T11:32:12Z"' +
' }, {' +
' "id": 105,' +
' "personId": 4,' +
' "date": "2023-10-15T00:00:00Z",' +
' "allowanceCatalogId": 10,' +
' "allowanceSurchargeNo": "10",' +
' "dirt": 9,' +
' "workingHours": 2.25,' +
' "createdAt": "2023-10-16T15:00:55Z",' +
' "updatedAt": "2023-10-16T15:00:55Z"' +
' }' +
' ]' +
'}';
var lObj := TJsonBaseObject.Parse(s) AS TJsonObject;
try
var workingHours := lObj['data'].Items[0].F['workingHours'];
ShowMessage(FloatToStr(workingHours)); // shows 2.5
finally
lObj.Free;
end;
end; Do you have a different result? |
Hi!
I have vom JSon Objects with floating point number values in it.
For example:
{
"name": "Mr. Smith",
"value": 1.23
}
But evertime I want to parse the object via TJsonDataObjects I get the integer part backe, so 1
and not 1.23. This happens everytime I convert a json string to a jsonobject with a floating point number in it.
Any idea why?
Thanks!
The text was updated successfully, but these errors were encountered: