Merge pull request #1417 from rts-cn/fix-lua-json

[mod_lua] fix json encoding of lua number string
This commit is contained in:
Andrey Volk 2021-11-01 19:00:35 +03:00 committed by GitHub
commit f96f83ee3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
if (lua_isnumber(L, -2)) {
if (lua_type(L, -2) == LUA_TNUMBER) {
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)));
} else if (lua_isboolean(L, -2)) {
} else if (lua_type(L, -2) == LUA_TBOOLEAN) {
ADDITEM(*json, key, cJSON_CreateBool(lua_toboolean(L, -2)));
} else if (lua_isnil(L, -2)) {
ADDITEM(*json, key, cJSON_CreateNull());

View File

@ -108,5 +108,11 @@ freeswitch.consoleLog("INFO", ret .. "\n")
ret = json:execute2(json:encode(cmd))
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)
stream:write("+OK")