It looks like you're new here. If you want to get involved, click one of these buttons!
require("json") local a = json.encode( { 1, 2, 'fred', {first='mars',second='venus',third='earth'} } ) print( a) local b = json.decode( a) print( b)
print(b[3])
print(b[4].first)
function print_r (t, indent, done) done = done or {} indent = indent or '' local nextIndent -- Storage for next indentation value for key, value in pairs (t) do if type (value) == "table" and not done [value] then nextIndent = nextIndent or (indent .. string.rep(' ',string.len(tostring (key))+2)) -- Shortcut conditional allocation done [value] = true print (indent .. "[" .. tostring (key) .. "] => Table {"); print (nextIndent .. "{"); print_r (value, nextIndent .. string.rep(' ',2), done) print (nextIndent .. "}"); else print (indent .. "[" .. tostring (key) .. "] => " .. tostring (value).."") end end end --then do print_r(b)
Likes: ar2rsawseen
Comments
Uploading finished.
[1,2,"fred",{"first":"mars","third":"earth","second":"venus"}]
table: 07F5BD48
pls try the 5 lines of code, you should get the same result.
To show it all in the console you can use a recursive print function
Likes: ar2rsawseen