地產(chǎn)公司做網(wǎng)站維護寫代碼么莆田百度seo公司
一、前言
項目lua使用工具:cjson
問題:reids中部分數(shù)據(jù)的json key存在為[]的值,使用cjson進行解析的時候將原本空數(shù)組[]解析成了空對象{}
目標:原本[]? 轉 []
二、解決方案
在使用cjson類庫時,先配置json轉換要求
-- 設置json轉換格式 cjson.encode_empty_table_as_object(false) |
三、代碼片段
local cjson = require ("cjson") -- 設置json轉換格式 cjson.encode_empty_table_as_object(false) ? if ngx.null ~= rescontent then ? -- 不為空 ? -- rescontent為redis查出的json內(nèi)容 ? ?local status, json_body = pcall(cjson.decode, rescontent) ? if not status then ? ? ? ? ? --rescontent不是json,就返回rescontent本身 ? ? ? else ? ? ? rescontent = json_body ? end ? core.rsp("0", "成功", "",{}, rescontent, "lua.rp") ? return else |
四、結果
????????