function tableToString(studentNum) local str = "{ " str = str.." " for k, v in pairs(studentNum) do if type(v) ~= "table" then str = str.."[""..k..""]" str = str..":" str = str..v str = str.."," str = str.." " else str = str.."[""..k..""]" str = str..":" str = str..tableToString(v) str = str.."," str = str.." " end end str = string.sub(str, 1, -3) str = str.." " str = str .." }" return str -- print("tableToString===", str) end local studentNum = {1, {6, 7, {"hello", "world"}}, 5} local str = tableToString(studentNum) print(str)