Skip to content

Conversation

@JieTrancender
Copy link

…ontains null

A null pointer substitution is currently used while parsing a string contains null, which is not expected by those who are unaware of this rule. Is it better to keep the semantics as they are?


/* In Lua, setting "t[k] = nil" will delete k from the table.
 * Hence a NULL pointer lightuserdata object is used instead */
// lua_pushlightuserdata(l, NULL);

The changed test code and output are shown below, perhaps more as expected

local tbl = {1, nil, "hello world"}
local encodeStr = json.encode(tbl)
print("encodeStr", encodeStr)
local decodeTbl = json.decode(encodeStr)
for k, v in pairs(decodeTbl) do
    print(k, v)
end
encodeStr = json.encode(decodeTbl)
print("encodeStr", encodeStr)
decodeTbl = json.decode(encodeStr)
for k, v in pairs(decodeTbl) do
    print(k, v)
end

local tbl = {a = "a", b = "b", c = "c"}
encodeStr = json.encode(tbl)
print("encodeStr", encodeStr)
decodeTbl = json.decode(encodeStr)
for k, v in pairs(decodeTbl) do
    print(k, v)
end

encodeStr = json.encode(decodeTbl)
print("encodeStr", encodeStr)
decodeTbl = json.decode(encodeStr)
for k, v in pairs(decodeTbl) do
    print(k, v)
end

输出:
encodeStr	[1,null,"hello world"]
1	1
3	hello world
encodeStr	[1,null,"hello world"]
1	1
3	hello world
encodeStr	{"c":"c","b":"b","a":"a"}
c	c
b	b
a	a
encodeStr	{"c":"c","b":"b","a":"a"}
c	c
b	b
a	a

@JieTrancender
Copy link
Author

CC please. @mpx

rzanol pushed a commit to rzanol/lua-cjson that referenced this pull request Sep 21, 2023
@onlytherailgun
Copy link

It seem that the pr have not merge into master branches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants