0

i have JSON responce like this:

{"ts":"1026","updates":

[{"type":"message_new","object":{"message":

{"date":1588966108,"from_id":329211115,"id":0,"out":0,"peer_id":2000000003,"text":"test"}}},

{"type":"message_new","object":{"message": 

{"date":1588966109,"from_id":329211115,"id":0,"out":0,"peer_id":2000000003,"text":"test2"}}}]}

How to print an "text" field?

I have this responce converted to Lua table.

I tried to call

answer["updates"]["object"]["message"]["text"]

, but i had error 'attempt to index a nil value (field 'object')'

1 Answer 1

2

updates is an array. So use

answer["updates"][1]["object"]["message"]["text"]

or

answer.updates[1].object.message.text
Sign up to request clarification or add additional context in comments.

2 Comments

print(answer["updates"][1]["object"]["message"]["text"]) return error 'attempt to index a nil value (field '?')'
@385i, inspect your table with for k,v in pairs(answer.updates) do print(k,v) end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.