I spent a good portion of this evening tearing my hair out, wondering why Corona was blowing out my array when JSON saving and loading a table that has an index of 0.
json = require( "json" ) local t, j = {}, {} for i = 0, 10 do t[i] = math.random( 10 ) end print ( "Table size: " .. #t .. " / " .. json.encode( t ) ) saveTable( t, "test.txt" ) j = loadTable( "test.txt" ) print ( "Table size: " .. #j .. " / " .. json.encode( j ) ) print ( j[0] )
Using the above code, it will create a table of 11 elements full of random numbers.
When run, #t will curiously return a value of 10.
But, when you load the same table back into a new variable, the value of #j returns 0. And, if you attempt to get the value of the j[0], it returns nil.
Table size: 10 / {"1":8,"2":2,"3":10,"4":10,"5":8,"6":9,"7":10,"8":3,"9":6,"10":5,"0":3} Table size: 0 / {"1":8,"0":3,"3":10,"2":2,"5":8,"4":10,"7":10,"6":9,"9":6,"8":3,"10":5} nil
This is using Daily Build 2013.1053.