Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua 5.3 to add integer #33

Open
teahouse opened this issue Jun 1, 2016 · 4 comments · May be fixed by #90
Open

lua 5.3 to add integer #33

teahouse opened this issue Jun 1, 2016 · 4 comments · May be fixed by #90

Comments

@teahouse
Copy link

teahouse commented Jun 1, 2016

local cjson = require "cjson"

local tab = {}
tab[10] = 199
tab.pp = "fan"
local estr = cjson.encode(tab)
print("-------------", estr)
local totab = cjson.decode(estr)
for k,v in pairs(totab) do
print("---fff-------", k,v)
end
the question : 199 change to 199.0, so bad when i use to json protocol to communicate with client!
how to solve it, please.
thanks!

@teahouse teahouse closed this as completed Jun 2, 2016
@teahouse teahouse reopened this Jun 2, 2016
@teahouse teahouse closed this as completed Jun 2, 2016
@teahouse
Copy link
Author

teahouse commented Jun 2, 2016

i think of an clumsy solution.we can edit the file lua_cjson.c.
case T_NUMBER:
{
if(token->value.number>(int)(token->value.number))
lua_pushnumber(l, token->value.number);
else
lua_pushinteger(l, token->value.number);
break;;
}

@teahouse teahouse reopened this Jun 2, 2016
@mpx
Copy link
Owner

mpx commented Aug 24, 2016

The JSON numbers are floating point (a superset of integers). Any code consuming JSON needs to handle floating point numbers to avoid problems.

Attempting to auto-detect between floats and integers will reduce performance and is likely to cause surprises elsewhere.

@martin-eden
Copy link

Just tested it versus another JSON parsers. Great performance but sample result file 4% bigger due ugly ".0" after any number. Also lua 5.3 natively support int64 while I'm sure cjson returns floats.

So I'll refrain from using it. Fast but not correct.

@jason-fan
Copy link

Just tested it versus another JSON parsers. Great performance but sample result file 4% bigger due ugly ".0" after any number. Also lua 5.3 natively support int64 while I'm sure cjson returns floats.

So I'll refrain from using it. Fast but not correct.

the clone branch https://github.com/cloudwu/lua-cjson

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 a pull request may close this issue.

4 participants