[lua]判断nginx收到的是否json
本站寻求有缘人接手,详细了解请联系站长QQ1493399855
local post_data = ngx.req.get_body_data()--[[ngx.log(ngx.ERR, 'post data:', post_data)]]local ok, res_tab = pcall(cjson.decode, post_data)if not ok then ngx.log(ngx.ERR, 'post data is not json!', post_data)get_respone(Result_Code.Error)returnend-- 真正判断是否jsonpost_data = string.gsub(post_data,""{","{")post_data = string.gsub(post_data,"}"","}")post_data = string.gsub(post_data,"\","")local ok, res_tab = pcall(cjson.decode, post_data)if not ok then ngx.log(ngx.ERR, 'post data is not json!', post_data)get_respone(Result_Code.Error)returnend