Reputation: 8920
Here is my part of the code that decode json:
local bests = json.decode(event.response)
print(event.response)
and it prints in the console
[{"id":"73","userID":"2","userName":"Test","userLastname":"Test","score":"3"}]
but when I am trying the following:
print(bests.userName)
returns nil
print(bests[0].userName)
error
print(bests.userName[0]) error
I've try any combination and it doesn't seem to work, what is my mistake?
Upvotes: 2
Views: 423
Reputation: 80639
As Egor already replied in comment, indexing starts with 1
in Lua. For future references though, while debugging the program, you should use an iterator to find out how the table is stored.
for k, v in pairs(bests) do
print( k, v )
end
Upvotes: 1