Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Lua table gives nil and JSONEncode fails?

Hi!

Im currently programming a flightplan that gets its data from trello (with the trello api). Everything works fine and the table it gets looks like a lua table (table: 32691AA4) When i JSONEncode it, it looks like this:

[{"pos":81919,"closed":false,"subscribed":false,"id":"secret","idBoard":"secret","name":"ada"},
{"pos":147455,"closed":false,"subscribed":false,"id":"secret","idBoard":"secret","name":"sds"},
{"pos":212991,"closed":false,"subscribed":false,"id":"secret","idBoard":"secret","name":"dfd"}]

(I replaced the ids with secret for safety purposes and to shorten it) - You need to press view source to see it completly

now if i JSONEncode the table with a [1] after it, it gives me this:

{"pos":81919,"closed":false,"subscribed":false,"id":"secret","idBoard":"secret","name":"ada"}

-Press view source to see everything As you can see, everything works fine. (btw if i print it without JSONEncode it looks something like this: "table: 311523A4")

Now if i JSONEncode it with [1][1] after it, it gives me this:

Argument 1 missing or nil

(The result without JSONEncode is nil for some reason)

How can i fix this problem and as example only get the "pos" string?

1 answer

✓ Accepted answer

This is because the table that everything is in is an array, which is why [1] works. However, [1] is a table. [1][1] gives you nil because [1][1] is nil. [1][pos] gives you the "pos" item in the table, which is 81919. [1][subscribed] would give you false. Etcetera.

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.