[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Which JSON parser with 5.3?
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 15 Apr 2017 16:21:17 +0200
Thanks, this one satisfies the conditions. Unfortunately, it is
too strict for the JSON produced by the webpage. Example:
[{"items":[];"date": "2017-04-15"}]
produces
nil Missing a comma or '}' after an object member. (12)
I'm not a JSON expert, so can't comment on the validity of the
original string, but I have no control over the webpage that
produces it.
In the meantlime, by Murphy's Law, the PHP page has thrown up
an nested list, so the fallback decoder is now:
function json_decode (s)
local function do_json_list(s,is_list)
if is_list then s = s:sub(2,-2) end
s = s:gsub("(%b[])()",do_json_list)
if is_list then s = '{' .. s ..'}' end
return s
end
local t = load('return '..do_json_list(s):gsub('("[%w_-]-"):','[%1]='))
if t then return t() else return s end
end
2017-04-15 14:51 GMT+02:00 Xpol Wan <xpolife@gmail.com>:
> There is my binding to rapidjson: https://github.com/xpol/lua-rapidjson
> Or just luarocks install rapidjson
>
> 云风 Cloud Wu <cloudwu@gmail.com>于2017年4月15日 周六下午4:40写道:
>>
>>
>>
>> Dirk Laurie <dirk.laurie@gmail.com>于2017年4月15日周六 上午5:45写道:
>>>
>>> I used to like lua-cjson but it does not sit well with Lua 5.3.
>>> Whenever a string could represent a number, it converts
>>> it to a float, so that every integer prints with a .0 at the end.
>>>
>>> Any recommendations for a module that works under Lua 5.3
>>> and does not have this annoying feature?
>>>
>>
>> You can use my fork : https://github.com/cloudwu/lua-cjson
>>
>> My pull request : https://github.com/mpx/lua-cjson/pull/22