forked from Mirrors/freeswitch
Merge pull request #1417 from rts-cn/fix-lua-json
[mod_lua] fix json encoding of lua number string
This commit is contained in:
commit
f96f83ee3b
|
@ -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());
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue