Decoding of numbers in JsonDecoderAsync
miguelSantirso opened this issue · 1 comments
There is an issue when decoding numbers in JsonDecoderAsync
: I noticed that when there is some numeric value which is not at the end of the object, it is not stored correctly in the result. I tried with some basic objects to confirm it:
In the following example, number_b is correct but number_a is undefined.
{"number_a":1,"number_b":2}
In this one, only number_c is correct. number_a and number_b are undefined
{"number_a":1,"number_b":2,"number_c":3}
Apparently, the problem is that, in case 0x100, you first store the value of the number in "result" but then you only put it in the stack when you find a "}" character. I followed the execution of the program and confirmed that later, you just overwrite result and the value of those numbers is never saved.
I added the line of code that saves the value of the number to the case when there is a comma (instead of a "}" character) and it is working perfectly now. Here is the code, the line I added is the second one:
if (char === 0x2c) {// == ,
_stack[_stack.length - 4][_stack[_stack.length - 3]] = result;
_stack.pop();
_stack[_stack.length - 1] = 0x304;
} else if (char === 0x7d) {// == }
_stack[_stack.length - 4][_stack[_stack.length - 3]] = result;
result = _stack[_stack.length - 4];
_stack.length -= 4;
} else {
throw new Error("Unexpected ] while parsing object");
}
Good find, thank you for your help. I've added your changes to the repository.