You are not logged in.
Pages: 1
I'm trying to store a 14 digit barcode number as a RawUTF8 field. Occasionally a number will start with zero which causes a JSON parsing error.
As a work-around I could prefix all the numbers with an underscore but is there a better way?
Thanks
Offline
In which context is the parsing error occurring?
At low-level of the ORM, what is stored within a RawUTF8 should remain as stored.
Only when displayed, the column may be identified as a number, then triggering such an error.
Could you provide some code to reproduce the issue?
Offline
The parsing error is happening in javascript (jquery ajax call). It seems that a number starting with zero isn't strictly valid JSON.
The data is coming from an EPOS system which puts an underscore in front of the number. I was stripping it out as I couldn't see the point of it but it's probably easier to just leave it in.
Offline
In fact, when you retrieve a number starting with a 0, it is not a valid JSON number, unless the next character is '.' or a plain zero.
That is, '0', '0.123' are valid numbers, and '0123' is not.
And JSON does not allow '+' to indicate positive numbers (only '-' sign).
See http://json.org/
I did not know this, and find it to be weird.
Sounds like a C-like-behavior inherited into JavaScript (for octal/hexadecimal notation)...
I've modified the ORM source code to reflect this unexpected JSON definition, about '0' and '+'.
See http://synopse.info/fossil/info/7f82fd67bd
Thanks for the feedback.
Coming from a pascal point of view, this is "bizarre".
Offline
2 ab.
I use overridden version of TSQLTable.GetJSONValues (when expant=false I write resp in {"fields":["fld1", "fld2"], "data": [[val1, val2,..valN],[val1, val2,..valN],...[]]} - it's more native for JavaScript client, but found a bug in your and my code
function TSQLTable.GetJSONValues(
line: if IsString(U^) then begin
must be: if IsStringJSON(U^) then begin
it's important for string fields started from ZERO must me "code": "01", then IsStrint(U^) I got "code": 01 and JavaScript think code is integer..
may be exist other place where is changes necessary.....
I add ticket.
Offline
Nice catch.
I made a code review.
It should be fixed by http://synopse.info/fossil/info/eb2b772e52
Thanks for the feedback.
Offline
Pages: 1