I have incoming data, which I store in a variable messages
:
connection = ContextIO::Connection.new(key, secret)
messages = connection.all_messages(:account => account, :limit => 100, :since => (Time.now - 3000.day ))
The variable messages
is formatted in JSON. Then I execute this:
foo = JSON.parse(messages)['data']
Most of the time this works. Every now and again, I get this error message:
A JSON text must at least contain two octets!
That error message then refers to the line JSON.parse(messages)['data']
What is an octet?
Why must JSON text contain at least two octets?
How do I prevent my code from breaking every time messages
does not have two octets?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…