• Converting Tables in a table to a json string
    2 replies, posted
Hi all, I'm trying to convert every table in a table to a JSON string. Without luck. I have atm: [CODE]for _, table in pairs(localtable) do if istable(table) then localtable[table] = util.TableToJSON(localtable[table]) end end[/CODE] Why is it not working and what am I doing wrong? Thanks, Darrell.
[QUOTE=Darrell;47687097]Hi all, I'm trying to convert every table in a table to a JSON string. Without luck. I have atm: [CODE]for _, table in pairs(localtable) do if istable(table) then localtable[table] = util.TableToJSON(localtable[table]) end end[/CODE] Why is it not working and what am I doing wrong? Thanks, Darrell.[/QUOTE] You're setting the index of the table to the table itself; localtable[table] will ALWAYS be nil in that code. You need to set the index to the index of the original table and convert the value for that index to a JSON string. [code] for i, v in pairs(localtable) do if istable(v) then localtable[i] = util.TableToJSON(v) end end [/code]
[QUOTE=AK to Spray]-snip-[QUOTE] That makes sence, I was thinking that v would return the tablename, but because a loop works with keys and values that doesn't work. Now it works, thank you!
Sorry, you need to Log In to post a reply to this thread.