lunajson icon indicating copy to clipboard operation
lunajson copied to clipboard

size of array

Open jungjinki opened this issue 5 years ago • 1 comments

I am trying to get the size of an array. with json {"main":{"type":"1","paper":"A4"},"s1st":{"column":[1000,5,5],"text2":"text2str"}} t= json.decode( string, pos, null, arrlen ) I could get "1000" by t.s1st.column[1] and I expected to get 3 by t.s1st.column[0]. but error raisesd.

How can I know the size of "column" array ? Thank you in advance.

[email protected]

jungjinki avatar Apr 20 '19 22:04 jungjinki

With the Lua length operator ?

local rawjsondata = [[ {"main":{"type":"1","paper":"A4"},"s1st":{"column":[1000,5,5],"text2":"text2str"}} ]]
local t = require "lunajson".decode(rawjsondata)

print( #t.s1st.column )

tst2005 avatar Apr 23 '19 08:04 tst2005