I’m getting a weird result reading a json file back to the table.
Namely, I’m using a not-full two dimensional table (both with indices running from 1 to something) I saved at previous runs of my app, where some values are false, some true and the rest nil. Saved state looks something like this (has more data with it, but I trimmed it):
{"note":[{"2":false,"3":false,"7":true,,"22":false,"23":true},{"1":true,"10":true,"25":false,"26":true},{"27":true,"28":true,"19":true,"11":true},{"17":false,"13":true}]}
When I read it, assign it to my table, and then trying to get, say the value of note[1][22], i get nil. I tried two different approaches at printing a table - one with the pairs() function and the other with usual i=1,n style.
for i, val in pairs(M.note) do for j, vaj in pairs(M.note[i]) do print(i, j, M.note[i][j]) end end
With this approach, I get the values printed out corretly, even with correct indices i and j:
1 23 true 1 3 false ... 2 10 true ...
However, using second approach (the lengths of both dimensions are also in the file):
for i=1,M.firstDim do for j=1,M.secondDim do print(i, j, M.note[i][j]) end end
Here, the only value that is printed next to the increasing numbers of i and j, is nil. Why is it this way? Am I missing something?