龙空技术网

lua脚本处理json 并拼接字符串

flydragon 81

前言:

目前你们对“netjson字符串拼接”大体比较注意,你们都需要知道一些“netjson字符串拼接”的相关知识。那么小编也在网上汇集了一些对于“netjson字符串拼接””的相关内容,希望看官们能喜欢,朋友们一起来了解一下吧!

1,下载cjson并安装

sudo wget

sudo tar zxvf lua-cjson-2.1.0.tar.gz

cd lua-cjson-2.1.0

sudo make

2,代码

local cjson = require "cjson"local res=[[{"address":["北京海淀区1号楼","上海浦东区2号楼"],"userFlag":"old"}]]local data = cjson.decode(res)local number = table.getn(data["address"])if(number > 0) thenlocal voice="您共有"local address="个取件地址"local finalvoice={}table.insert(finalvoice, voice)table.insert(finalvoice,tostring(number))table.insert(finalvoice,address)if(number ==1) thentable.insert(finalvoice,",地址是:")elsetable.insert(finalvoice,",地址分别是:")endfor k,v in pairs(data["address"])doif(number >1) thentable.insert(finalvoice,tostring(k))table.insert(finalvoice,",")endtable.insert(finalvoice,data["address"][k])endfinalvoice=table.concat(finalvoice)print(finalvoice)end

标签: #netjson字符串拼接