I have a table with tables inside of that table, that is saved to the datastore encoded with JSONEncode. When I getAsync that table and want to see it all. How can I print that table in its entirety in english not with memory locations of the table inside? Is there a way anymore?
2.
tried : table.foreach() is depreciated and unpack(table) may unpack my embedded tables into another memory location table.
3. Tried
table.foreach()
unpack(table)
yes these were done inside of a loop
for key, value in pairs(data) do
print(key, typeof(value), value)
end
I hope my question makes sense.
Have you tried decoding the table with HttpService:JSONDecode
before modifying it
Use recursion with the type
method. For a deep table (nested tables), you need to recursively iterate through each subtable.
function search(t)
-- Base case: if param t is not a table then exit the recursive call
if type(t) ~= "table" then return end
for k, v in pairs(t) do
print(k, v)
search(v)
end
end
local a = {
alpha = {1, 2, 3, 4},
beta = {5, 6, 7, 8},
gamma = {9, 10, 11,
delta = {12, "epsilon"}
}
}
search(a)
This will recursively print every key-value pair as so:
-- Output
gamma table: 0x7f92cc3873b0
1 9
2 10
3 11
delta table: 0x7f92cc380820
1 12
2 epsilon
beta table: 0x7f92cc387370
1 5
2 6
3 7
4 8
alpha table: 0x7f92cc387330
1 1
2 2
3 3
4 4
Yes. i created a function to send the data I get from the datastore to decode it.
local function JsonDecoded(dataRecieved)
local saveData = HS:JSONDecode(dataRecieved)
return saveData
Sorry I thought the replies go to the people individually. But I will give @Negativize i test right now. Thank you.
Thank you @Negativize that definitely prints out the embedded tables. Was worried I was going to have to a.gamma, a.delta, a.alpha them to get what I was after. I’m curious why doesn’t it spread it out in the comment section like a hierarchy tree? in any case that is great. Thanks
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.