Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Lua table gives nil and JSONEncode fails?

Asked by
OKRPLAY 25
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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.

0
Thank you! OKRPLAY 25 — 6y
Ad

Answer this question