diff --git a/src/mod/languages/mod_lua/freeswitch_lua.cpp b/src/mod/languages/mod_lua/freeswitch_lua.cpp index 50d0778336..5d89aa28f9 100644 --- a/src/mod/languages/mod_lua/freeswitch_lua.cpp +++ b/src/mod/languages/mod_lua/freeswitch_lua.cpp @@ -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()); diff --git a/src/mod/languages/mod_lua/test/test_json.lua b/src/mod/languages/mod_lua/test/test_json.lua index b8f358f816..9ac2c06284 100644 --- a/src/mod/languages/mod_lua/test/test_json.lua +++ b/src/mod/languages/mod_lua/test/test_json.lua @@ -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")