LUA,多个数字字符串到数字



所以我使用web请求json:

{"number":"1,2,3"} OR table = {number="1,2,3"}

当我使用这个时,它显示数字:

typeof(1,2,3)

但是,当我直接从json/表中获取数据时,它会显示字符串,那么是否可以将其转换为数字?

Lua模式可能也是从原始字符串中获取数字的好选择;然后按照建议使用tonumber((,并将数字添加到示例代码中的表中,如下所示:

numbers = {}
str = '1,2,3'
for num in string.gmatch(str, '([^,]+)') do
table.insert(numbers, tonumber(num))
end

最新更新