Hello there, this might be something rudimentary, but i can’t seem to open/decode JSON files right.
for example, this piece of code:
local t1 = {pika={99}, tika=22 }
local t2 = {pika={77}, tika=44 }
local t = {t1,t2}
local tj = json.encode(t)
local p= system.pathForFile("test.json", system.DocumentsDirectory)
local pf= io.open(p,"a")
pf:write(tj)
io.close()
local of=io.open(p,"r")
local c=of:read("\*a")
local td = json.decode(c)
io.close()
print("TJ TD",tj, td[1], td[2].tika,#td,c)
prints me :
TJ TD [{“tika”:22,“pika”:[99]},{“tika”:44,“pika”:[77]}] table: 0x11721c5f0 44 2
[{“tika”:22,“pika”:[99]},{“tika”:44,“pika”:[77]}][{“tika”:22,“pika”:[99]},{“tika”:44,“pika”:[77]}][{“tika”:22,“pika”:[99]},{“tika”:44,“pika”:[77]}][{“tika”:22,“pika”:[99]},{“tika”:44,“pika”:[77]}]
The problem for me is with the table that json.decode() serves me. It only counts the number of table elements to 2, which are the first table [{“tika”:22,“pika”:[99]},{“tika”:44,“pika”:[77]}], and ignores the other instances of it in the file.
I have no idea how to make sure i get a table for every entry and so forth.
The file was formed with repetetive writing, is there any particular way i should have formatted that?
Thank you for any assistance! [import]uid: 125838 topic_id: 32078 reply_id: 332078[/import]