zoukankan      html  css  js  c++  java
  • [lua]判断nginx收到的是否json

    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)
            return
        end
    
        -- 真正判断是否json
        post_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)
            return
        end
  • 相关阅读:
    9.17 HTML CSS
    9.16
    9.15
    9.14
    9.13
    9.12
    9.11
    9.10
    9.9
    9.8
  • 原文地址:https://www.cnblogs.com/linn/p/4727397.html
Copyright © 2011-2022 走看看