[mod_lua] fix json encoding of lua number string

This commit is contained in:
Seven Du 2019-05-21 17:12:36 +08:00 committed by Seven Du
parent 9f26a15220
commit fe296e4fa3
2 changed files with 9 additions and 3 deletions

View File

@ -568,11 +568,11 @@ void JSON::LuaTable2cJSON(lua_State *L, int index, cJSON **json)
switch_assert(*json); switch_assert(*json);
if (lua_isnumber(L, -2)) { if (lua_type(L, -2) == LUA_TNUMBER) {
ADDITEM(*json, key, cJSON_CreateNumber(lua_tonumber(L, -2))); ADDITEM(*json, key, cJSON_CreateNumber(lua_tonumber(L, -2)));
} else if (lua_isstring(L, -2)) { } else if (lua_type(L, -2) == LUA_TSTRING) {
ADDITEM(*json, key, cJSON_CreateString(lua_tostring(L, -2))); ADDITEM(*json, key, cJSON_CreateString(lua_tostring(L, -2)));
} else if (lua_isboolean(L, -2)) { } else if (lua_type(L, -2) == LUA_TBOOLEAN) {
ADDITEM(*json, key, cJSON_CreateBool(lua_toboolean(L, -2))); ADDITEM(*json, key, cJSON_CreateBool(lua_toboolean(L, -2)));
} else if (lua_isnil(L, -2)) { } else if (lua_isnil(L, -2)) {
ADDITEM(*json, key, cJSON_CreateNull()); ADDITEM(*json, key, cJSON_CreateNull());

View File

@ -108,5 +108,11 @@ freeswitch.consoleLog("INFO", ret .. "\n")
ret = json:execute2(json:encode(cmd)) ret = json:execute2(json:encode(cmd))
freeswitch.consoleLog("INFO", ret .. "\n") freeswitch.consoleLog("INFO", ret .. "\n")
sn = json:encode({s = "1001", n = 1002})
freeswitch.consoleLog("INFO", sn .. "\n")
ret = json:decode(sn)
assert(ret.s == "1001")
assert(ret.n == 1002)
-- assert(false) -- assert(false)
stream:write("+OK") stream:write("+OK")